Range Selection With Variable

Jan 27, 2010

I am using Selection.ClearContents command to clear data from column F and G. I know the last row as 230 but the starting row is the first empty cell which I find using Do While loop in range F31 to F230. The variable that stores the first empty cell number is 'r'.

Range("F &r:G230").Select
Selection.ClearContents

View 3 Replies


ADVERTISEMENT

Change Range Selection With A Variable

Feb 19, 2009

How do I change the selection of a range with a variable, and not a hardcoded number in XL2003? I have to update a set of spreadsheets every month, and it's a hassle to have to constantly open my pivot table worksheet, copy, open the summary worksheet, paste ... etc. etc. etc. The code below is my attempt at creating a ComboBox with "January, February, March, etc." and every time I select a particular month it will automatically copy data from my pivot table worksheet into my new summary worksheet in the correct column. The range of data from my pivot table worksheet will never change, so I have no problem hardcoding that in, but based on which month is selected will alter which column the data goes in in the new worksheet.

I want to be able to write code for one month (say January) and then when I want to use a different month (say February) I can just change the column number and call up the originial January code.

Private Sub ComboBox1_Change()
Dim ColNum ' This is the variable I want to change based on which month is called
If ComboBox1.Value = "January" Then
ColNum = 1 ' Column number for Column A- Where my January column is
Elseif ComboBox1.Value = "February" Then
ColNum = 2 ' Column number for Column B- Where my February column is
' etc. etc. for each month
End If
Call January
End Sub

Private Sub January()
' Just a quick msgbox to make sure the previous macro is calling this one
MsgBox "Is this macro running?", vbQuestion + vbYesNo, "Check"...........................

View 9 Replies View Related

Range Selection From Variable Start Point

Dec 31, 2008

I'm trying to write a bit of code that will allow me to clear some sheets. One of the sheets has formula for x number of rows, and these need to be left intact. Under these forumla there is an area where data is pasted, and this needs to be cleared becfore starting the process.

Colum A is blank, apart from cell A1 (the column heading) and another cell (variable row) with the value 'Paste here'. I've used this variable cell in other macros on the sheet as a marker, so need this to stay. I was going to use this code below, but I don't know how to tell it to select from the current active cell to the bottom of the spreadsheet.

View 5 Replies View Related

Determine Maximum / Minimum Value And Additional Count From Variable Range Selection

Mar 25, 2014

I have been trying to determine the maximum/minimum value and additional count from a variable range which then I can use to subtract the first data of the range; I have been able to do that for a fixed range but not a variable one.

I have Column A with random positive numbers.

I have Column B with random negative numbers.

I have Column C with random numbers.

I have Column D with random numbers.

I have Column E with random 0’s and 1’s.

I have a set of 1600 cells of numerical data on each of the columns and there will be times when the random 0’s and 1’s from Column D will have appear repeatedly before changing to the opposite number, fx, I will get 7 nr. 1s before I get a 0 (zero).

I have been able to obtain the values in 2 cells within a fixed range:

If the last 8 cells in Column D have been “1” then I do:
F1=MAX(A1:A8)
G1=INDEX(C1:C8;MATCH(9.99999999999999E+307;C1:C8)) ---(Which provides the first number of the range in Column C after Column D has changed from 0 in D9 to 1 in D8)
H1=(F1-G1)

If the next 3 cells in Column D have been “0” then I do:
F9=MIN(B9:B11)
G9=INDEX(C9:C11;MATCH(9.99999999999999E+307;C9:C11)) ---(Which provides the first number of this range after Column D has changed from 1 in D12 to 0 in D11)
H9=(G1-F1)

Additional to this, the COUNT has also been challenging since I want to obtain in Column I, the COUNT of repeated 1’s from each range of 1’s in Column D; and also in Column J the same but for 0’s.

Fx:I18 (size of the range of 1’s originated from D1:D8)
J93 (size of the range of 0’s which consist to be the next range before 1’s were originated)
I12X (size of the range of 1’s which consist to be the next range before changed to 0’s)

However, that only works for a fixed range and continuous updates are made.

Book1.xlsx

View 2 Replies View Related

Variable Column Range Based On Current Selection For Sorting Columns

May 16, 2014

The first line of the code chooses the columns to select; all columns until there is no value. From there I need to have it sort those columns based on row 1. The problem is that the columns chosen are variable. It could be columns I:N (as shown below) or column G:Z or any other combination. (The code below was recorded if that matters at all.)

View 2 Replies View Related

Save Average Of A Variable Selection To A Variable

Dec 9, 2008

I have looked at many different examples of uses of the average function but I haven't found any examples of what I need it to do. Here is the code I am trying to use, but I am getting some errors.

View 6 Replies View Related

Variable For Row / Column Selection

Sep 13, 2007

I need to create a macro that clears the contents of a range of cells. However, that range of cells is variable.

I know my starting cell (C9) and I know the selection goes over to column Z every time but the number of rows I want to clear after that may change.

Also, whatever that first cleared range is, I would need to skip the row below it then clear the same number of rows below that. (not entire row of course, just the ones from column C to column Z)

View 9 Replies View Related

Variable Selection Delete

Apr 5, 2007

I have a macro that prints out schedule information for my production lines. I recorded the macro and made a few changes. What it does is print out the page header, delete about a dozen lines and then print the remainder of the schedule. Often the the remainder of the schedule is not all relevant data as production has completed orders. What i want to do is, using an input box, ask the user what worksheet row he wants the body of the schedule to start printing from. Here is what i have now.

Sub auto_open()
Workbooks.Open Filename:="S:BI-K11.xls", UpdateLinks:=3
Application.WindowState = xlMaximized
ActiveWindow.SmallScroll Down:=-3
Rows("7:13").Select
Selection.Delete Shift:=xlUp
Range("A1:O26").Select
Selection.PrintOut Copies:=1, Collate:=True
roww = InputBox("Rows")
Sheet1.Range("A1").Resize(roww + 10, 2).PrintOut

Workbooks.Open Filename:="S:BI-K21.xls"
Rows("7:19").Select...............................

is where i would like the number 13 to represent the input box variable so that the rows to be deleted would be from 7 to "last row to be deleted - 1"

View 8 Replies View Related

Making Variable Selection From Cells

Oct 13, 2011

I have a question about making a variable selection.

In cell X25 is written "B9" and in cell Y25 is written "M39".

Now i want to make a selection by a macro from cell B9 to cell M39.

View 1 Replies View Related

Variable Selection To Return Highest Value

Dec 12, 2011

If the weight selected is between the ranges e.g 1.5kg for England so that it returns the higher value 10.69. At the moment if I put in the vlookup formula it returns the lower value of 9.60.

Weight KGEnglandScotlandWales0.59.109.109.101.09.609.109.702.010.6910.6910.693.012.2812.2812.28

View 4 Replies View Related

Put Print Dialog Box Selection Into A Variable

Jan 16, 2012

Is there a way to have the print dialog box come up, make a selection, and put that selection into a variable?

Ex:

Code:

Application.Dialogs(xlDialogPrint).Show

brings up the print dialog. I need to be able to select the printer and have the selected printer put into a variable in my vba code.

I have tried Ex: w=Application.Dialogs(xlDialogPrint).Show, but all I get is w=true

The reason I need it is because I will be printing via vba code, but the printer may vary for different print jobs.

View 6 Replies View Related

Random Option Selection Based On Variable Input

Jul 23, 2009

I need an action to allow for the random selection of a predetermined series of number codes which represent a given letter.

It is probably easier to look at the attached sheet and the previous discussion to see what I mean.

Previous discussion:
http://www.excelforum.com/excel-work...-of-cells.html

View 2 Replies View Related

Hide Rows With Variable Text Based On Dropdown Selection

Jun 11, 2014

I have a spreadsheet which contains our fleet information covering many vehicles in one list. The teams for these vehicles are listed in Column A. What I would like to have is:

A dropdown box to pick from All, or the various teams in A1To hide every row that doesn't match the selection of A1To reveal every row that contains the selection for A1 at any point in column A. e.g: "*Dog Team*"

This is because something might be listed as "Moved from Dog Team" or "Dog Team, temporarily on loan", or "Dog Team V66.m"

I have taken a small sample of the data I will be working from and made a very simple drop down box which displays the pages of information for the vehicles by hiding/unhiding blocks of columns:

Code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" Then
If Range("A2") = "MOT/Service" Then
ActiveSheet.Columns("A:P").EntireColumn.Hidden = False
ActiveSheet.Columns("Q:CE").EntireColumn.Hidden = True
ElseIf Range("A2") = "Contact Details" Then

[Code]....

But because there is also filters on the sheet, meaning the positions of the entries based on rows can change, I need it to search for the "*xyzzy*" method, but am unsure how to do this! While just using the Filters will work, due to some human limitations I have been asked to have a specific drop down box in a very specific location with instructions next to it.

View 1 Replies View Related

String Variable To Call Defined Range Variable

Nov 10, 2006

Say you define a public range variable called Inputworksheet and you set it to refer to the worksheet called Inputworksheet. You have a separate string variable with the value Inputworksheet. How do you get this string variable value to call/control the range variable Inputworksheet?

I am getting an excel worksheet value from a lookup function that corresponds to the name of a VBA range variable. Once I have this worksheet value, I would like to use the range variable that has the same name as the worksheet value.

View 5 Replies View Related

Autofill With Range That Is Column Variable And Row Variable

Apr 4, 2008

I am trying to autofill dynamic ranges that have column variables (d) and row variables (x)... I am having a hard time with the syntax on this

View 9 Replies View Related

Set Range Variable Using Variable Row Number

Mar 11, 2008

I am using a variable named " Totals" as a range type to refference the range in a formula. It works the way I have it.

Dim Totals As Range
Set Totals = [U37: AE37]

Now instead of the absolute refference, I would like to change the row refference by an offset of my current row, using a formula with a varriable. The columns stay the same.

View 3 Replies View Related

Autofill In Macro Range Is Constant How Can I Code To Be A Variable Range?

Feb 19, 2010

I am trying to write a macro which will autofill specific columns. The macro will set the range from the start of my autofill to the end of my autofill as a constant range.

The problem I need to get around is the end of my range can always change each time I run the macro. For instance, the first time I run the macro I may only need to autofill from row 4 to row 15. The next time, I may only need to autofill from row 4 to 23 (because of user updates). How can I make the end of my range not be a constant address but variable?

View 6 Replies View Related

Select Range In Worksheet Where Last Cell In Range Is Variable?

Jan 27, 2012

I am trying to write code to select a range in a worksheet where the last cell in the range is variable.

Sub DataTest()
Dim LastColumn As Integer
Dim LastRow As Long
Dim LastCell As range

[Code].....

View 8 Replies View Related

About Range Selection

Jul 22, 2009

A question regarding "AboutRangeSelection" procedure on Chapter 11 in the **, Excel 2003 Power Programming with VBA by John Walkenbach.

View 3 Replies View Related

Deriving Range From A Selection

Jan 20, 2010

I am trying to figure out how to derive a range from a selection. Here is the code i am using to select the table.

View 5 Replies View Related

Dynamic Range Selection

Feb 8, 2010

I am filtering a list in Column H and depending on what criteria I filter on I need to be able to select only what I have actually filtered for. I am using the code below to find the lower right corner of my range that I'm trying to select and this works great.

View 3 Replies View Related

If Range Selection Does Not Match Value Then

Mar 7, 2012

VBA IF statement that references the below code. the IF statement would say if the below selection does NOT match 'putname' then

Code:
Range(Selection, Selection.End(xlDown)).Select

View 2 Replies View Related

Cell Selection Over Given Range

Apr 8, 2014

I'm looking to go to every 8th cell in a column when I hit the enter key. I was thinking of selecting a small range say from A2 which is zero to A10 which would also be zero then A18 which is zero. The reason being I have a lot of figures to put in to each zero cell then I select "Series" to fill the cells in-between with the incremental figures between the two zeros which would be the difference between the two zero figures.

View 2 Replies View Related

If Statement With A Range Selection

Aug 9, 2007

I was making a simple spreadsheet as I'm taking practice tests for some IT certifications and the spreadsheet I was making was to chart out my progress.

I had a range of scores in some cells and one of the formulas I used so that I didnt have errors in the sheet like div/0 went like the following:

=if(b5:b50="","",sum(b5:b50)) this seemed to work really well for the one section, however I tried to get a little fancy as always and I think I messed something up. Beneath that I tried to separate each practice test with the same sort of formula resulting something like the following:

=if(b30:b40="","",sum(b30:b40)) this however just returned an error #value. I dont understand why the first formula worked and the second didnt. Then again, I'm not really an excel guru, back in college I was really good with it but I dont really remember much.

View 9 Replies View Related

Range Selection Query

Feb 27, 2009

I'm writing a couple of macros which require selection of a range. The user could either select the range before executing the macro or if range has not been pre-selected, an inputbox should pop-up through which the user can select required range.

View 9 Replies View Related

Assign Named Range To A Vba Range Variable?

Jan 25, 2013

I have a named range, called SubjectNamesPastoral on a worksheet called Worksheets("Group to Teacher")

I can't assign the named range to the rngSubjectFamilyRangeOnSubjectUsedSheet variable in vba.

the first two lines of code work fine, the msgbox shows "E100:E105", happy days!

However when I try to assign the same range to the rngSubjectFamilyRangeOnSubjectUsedSheet variable, the debugger runs past the 'Set' line without error, but throws 'error 91' at the second msgbox.

VB:
thisString = "SubjectNames" & strSubjectFamilyOfGroup

MsgBox Range(thisString).Address

Set rngSubjectFamilyRangeOnSubjectUsedSheet = Worksheets("Group to Teacher").Range(thisString)

View 1 Replies View Related

Copy A Range And Paste It Over A Variable Range

Jul 16, 2009

I am using the code below to copy a range and paste it over a variable range.

View 4 Replies View Related

Set Range Variable To Growing Dynamic Range

Mar 6, 2008

I have been working on part of the code for my spreadsheet and it works fine in the spreadsheet Databaseform however when I copied the code to my master spreadsheet Paul_PartLocDBCombo it does not work, I get the error:

Method range of object _worksheet failed
The code is then highlighted in yellow, the code is:
Set rng = wksPartsData.Range("a1", Range("a65536").End(xlUp))

Meaning this part is incorrect but I dont know why? To work it: go to Databaseform and press start. Enter 7mm in the product field and press find all. It will then return all the matching results in the userform. Its this I want to try and achieve on the other spreadsheet when the button find label is pressed.

View 3 Replies View Related

Chart With X-Axis Range Selection

Feb 26, 2014

I have excel file and need to create a chart with X axis to be scalable, by selecting (from drop down menu) - start and end dates.

View 3 Replies View Related

Range Selection And Origination Difficulty

Nov 3, 2008

I may not have the terminology right, but here's my problem:

With the Range Select Formula i.e.

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved