Select Cells Across Multiple Columns On Variable Row?

Nov 25, 2011

I'm trying to write some code to select cells in a number of columns on a variable row. I have the following code to define the rownumbers for Cash and Pal:

Selection.Find(What:="Total Cash", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _


Then I can use the following code to select a cell in a single column:

Range("P" & Cash & ":P" & Pal).Select

but I need to select cells in columns P, R, T, V, X, etc.....

If I was doing this for a fixed rownumber I would use:


but because my rownumber is variable I tried to use:

Range("P" & Cash & ":P" & Pal, "R" & Cash & ":R" & Pal, "T" & Cash & ":T" & Pal, "V" & Cash & ":V" & Pal, "X" & Cash & ":X" & Pal).Select

but this doesn't work giving the Compile error: Wrong number of arguments or invalid property assignments

View 4 Replies


Summing Variable Values Across Variable Sheets In Multiple Columns

Jun 27, 2014

I need a macro that will create a sheet at the end of the workbook.

Sum data from a variable amount of sheets and display that data on the created sheet.

Here is a step by step:

Starting on sheet 5.

Column D has a variable amount of part numbers in it. These part numbers would be different between the ascending sheets.

Column T, U, V has an inputed number in it that would need added up across all duplicate part numbers in all the sheets.

(Note: The data would also need started on row 4. Everything above row 4 is headers)

Here is a small example:

13019090W Part A1
68705500 Part B1
64202900 Part C-11
59634600 Part D1
26005300W Part E1

I need the macro to start with sheet #5(starting on row 4). Check to see if there is data in column T, U or V. If there is, to create a new sheet at the end. And copy the entire line into that sheet (starting on row 4).

After that, to check every sheet after (excluding the newly created one, starting on row 4) for data in Column T, U and V. And then check for duplicates in Column D on the newly created sheet. If there is a duplicate to add/subtract that number in Column T, U and V to the SUM in column T, U and V in the newly created sheet. If there is no duplicate, to copy the entire line to the new sheet.

So that when finished. On the new sheet, you have the SUM of T, U and V for everything that has data in T, U or V for all of the previous sheets, plus the entire line of the first instance (excluding the first 4 sheets).

View 2 Replies View Related

Copy Variable Sized Row And Paste Select Columns Into Different Worksheet

Sep 29, 2012

I'm in the middle of building a code that will look at the value in Sheet: "DATA" column "J", for each row that matches a criteria that I pull from a cell - Sheet: "Test" Cell: "C1".

The number of rows varies. I want to paste columns: "I2, K2:P2, U2:AJ2" when the value in Sheet: "DATA" column "J" matches the cell "C1".
I'm using a Command button to click every time I want to generate the filtered data. And I would prefer the code to always copy data starting at Sheet: "Test" Cell: "K2".

I've copied, below, my test code that I have so far which only copies row 2 from the Sheet: "Data", and copies it into Sheet: "Test", starting at K2.


Private Sub CommandButton2_Click()
If Sheets("DATA").Range("J2").Value = Sheets("Test").Cells(1, 3) Then
Sheets("Test").Cells(2, 11).PasteSpecial Paste:=xlValues, Operation:=xlNone
End If
End Sub

View 3 Replies View Related

Multiple Dropdown Select (multiple Columns)

Mar 4, 2009

I have VBA code below. Currently the code allows me in column "N" to choose more than one item in a dropdown menu. I am trying to find a way to make column K and M do the same thing. I have tried a number of ways but to no avail.

View 2 Replies View Related

Select Multiple Columns In VBA

Nov 1, 2012

To select multiple columns I can use Union but can I use something that will cicle through the values from an array?

Example (how do I see this)

VB :

columnsToDelete= array("UM","Post","Pre")
For i=0 To UBound(columnsToDelete)

Set columnsFound=Range("1:1").find(what:=columnsToDelete(i), lookin:=xlvalues,lookat:=xlwhole, matchcase:=True)
Selection delete
Next i

View 2 Replies View Related

Select Multiple Columns

Sep 15, 2008

I am using VBA to change the format of columns. The code work with 1 column, but In need to change the format of mulitiple columns. E.g Cols 11 to 22. I tried the code below but it does not work!

View 3 Replies View Related

ADO Select Distinct Multiple Columns

Aug 5, 2009

I am using ADO to select data from a CSV file, column 1 has some duplicate Incident numbers, but the rest of the columns the data may be different but not interested in that so I cannot use SELECT DISTINCT incident, desciption as this applies to all columns

so I tried the following

StrSQL = "SELECT DT.IncidentNumber, ST.Description -
FROM (SELECT DISTINCT IncidentNumber FROM " & StrFile & " ) DT -
INNER JOIN " & StrFile & " ST ON DT.IncidentNumber = ST.IncidentNumber"

however it returns ALL rows, if I use just

SELECT DISTINCT IncidentNumber FROM " & StrFile

I get the rows I am interested in but not the extra data I require

View 9 Replies View Related

SUMPRODUCT With A Variable Range Over Multiple Columns

Sep 15, 2014

I have an issue with SUMPRODUCT. My data is the budget for different items as follows

Column C has criterias such as Payroll, Expense or Fringes.
Column D has criterias such as "32", "43"
Column E to P are the numeric value (budget) by month (Period 01 to Period 12)

I am trying to create a formula that, for a given month, will sum the budget according to specific criteria.

For example, I want the value of the budget for "Payroll" + "32" for Period 1.

I managed to do that with the following formula:

E18 = 1
E16 = Fringes
E17 = 32


I used INDEX/MATCH so that the range into which the sumproduct will look for data to sum is variable and depends on what I want (I can easily change E18 to any period for which I would like to see my budget).

Now, I would like to take this to the next level and ask for a range of a column. For example, I would like to know the value of budget for "Payroll" + "32" for Period 01 + Period 02 + Period 03. How can I do that? I tried adapting the INDEX/MATCH but got no results.

Test on SUMPRODUCT.xlsx

View 6 Replies View Related

Select Multiple Cells Based On Multiple Criteria?

Sep 25, 2013

I would like a macro that select all cells based on multiple criteria. It's a big sheet, but I've made it smaller in the following example.

In row 1, there are 2 headers, in B1 (electricity) and C1 (gas) In column A, there are 3 houses, in A2, A6 and A10. The blocks of cells in between (e.g. B2:B5) have 2 headers, 'period' in B2, and 'account number' in B4. B3 and B5 have a list of options in them.

I want to select cells that meet certain criteria. Either electricity or gas, and either period or account number. So, if in cell D1 I choose electricity and in D2 period, I would like to select B3, B7 and B11. If I choose gas and account number, I wish to select C5, C9 and C13.

View 1 Replies View Related

Select And Copy Multiple Columns Based On 2 Data Fields

Feb 20, 2014

I have a spreadsheet with a heap of raw data in it. I need to perform a search based on a customer name, then return certain columns from the raw data IF the customer name is matched in one column, AND a special flag name is matched in a second column. The customer name is always a single entry for the purpose of the query, however the special flag must be checked against a possible list of values in a table. I know this is hard to explain, and I can't add attachments to my posts, so I have created a sample document and placed in in dropbox:

[URL] ........

View 9 Replies View Related

Append Variable In Variable Select Case Method

Feb 16, 2012

I want the select case list of a ComboBox to be treated as a variable in order to shorten the code size. To clarify the problem, i post the code with what i want to do, but don't know how to do it that way.


Select Case ComboBox1.ListIndex
Case 0: y = "AT"
For j = 0 To 26
Case "j": y = sheets("name").Range("A(j)") 'Range A(j) is a string, so y as well, as seen in Case 0.
Next j
End Select

Is something like this possible?

View 3 Replies View Related

Multiple Select Cells With Formula Only

Sep 29, 2008

Is it possible to select cells with conditions below using formula only?

Yes, VBA is easier, but I want to know if this is possible using formula.

1. selected cells (requested): A1, A3, A6, A10, A15 .... total 20 cells.

2. the increasement between them are: 2, 3, 4, 5, 6, 7, 8 ,,,,

View 9 Replies View Related

Multiple Active Cells - How To Select All Corresponding Rows

Apr 19, 2014

So for example if I have a1, a5, and a6 selected, I want to be able to select row 1, 6, and 7 in one action. Is there a hotkey for this, and if not what macro could I use?

ActiveCell.EntireRow.Select only gives me one row. I want to be able to select all of them at once.

View 1 Replies View Related

VLookup Select Multiple Cells And Sum Them In One Cell

May 16, 2014

I'm trying to make my vLookup select multiple cells and sum them in one cell

For example




Example 2 2
Example 2 3

The Vlookup would return the value of 2 for example 1 and 5 for example 2

View 2 Replies View Related

How To Move Variable Data Into Multiple Cells

Dec 16, 2011

I have 1 column with a varying amount of rows (around 2000+ rows) with data that is about 10 chars long. Since I cannot print it all on a few pages, I would like a way to re-orgnize the data into cells so I can print on as few pages as possible such that the qty of columns isn't wide then an 8.5 x 11 page.

One idea is the following.

Here's what i have.

Here's what i want.

Col1 Col2 Col3 Col4 Col5 Col6 Col7 ...
1 2 3 4 5 6 7
8 9 10 ...

View 1 Replies View Related

Multiple Columns Which Need To Be Combined With Some Columns Not Having All Cells Fill

Apr 30, 2014

I have a spreadsheet with 10 columns which are for tags for products. Some columns are filled in for 10 products and some are not. For instance, product 1 has 7 tags while product 2 has only 2 tags and so on. Now what I am looking to do is combine all the tags for each product with a "," inbetween each one. The problem is if I just use a simple =A2&","&B2&","&C2 etc formula is that if there are only 2 tags then I get 8 ","s. I also tried it with an IF statement but by the time I was done nesting items I became cross eyed and said there has to be an easier way to do this.

I have create a spreadsheet with the data and the result that I typed into the "result" column.

View 3 Replies View Related

Select Random Cells From Multiple Sheets And Copy

May 10, 2014

I would like to select say 2 id from sheet1 and 2 names from sheet 2 randomly and copy to sheet3, to cells a and b,have seen various codes but none seem to fit the bill.

View 3 Replies View Related

Select A Variable Based On A Variable

Jun 18, 2009

On my userform I have 20 comment icons (imported pictures), that when clicked need to bring up an InputBox for the user to add a comment, and store that comment in a Public variable specific to that comment which will later be written to the spreadsheet.

To keep it simple, lets say I have two comment icons to click, one to add comments to the "Testing Completed?" field, and one to add to the "Sign-Off?" field.

The first comment icon is named TestCompIcon, the second is SignOffIcon, and the public variables they write to are called TestCompComment and SignOffComment respectively.

To avoid having to code the InputBox procedure for every comment icon on the userform, I was hoping that upon click, the icon would call a centralized routine that would establish the name of the variable that needs to be written based on the name of the icon comment that was clicked. Something like as follows:...............

View 9 Replies View Related

Place Value In Multiple Cells Based On Cell Variable

Nov 26, 2009

I'm trying to place the value of "X" in multiple cells based on a cell variable (i). For example, if (i) is evaluates to 35, the following code ...

View 8 Replies View Related

Populating Fields In Multiple Cells Based On Criteria In Multiple Columns?

Feb 24, 2014

Im struggling to find a formula to populate cells based on values to be checked in two fields (ICODE, COMPANY) as shown below.

In the example here, all records where ever the ICODE = 49, i need to populate the fields(columns) AD1,AD2,AD3 or AD4 with the product name of the same company where the ICODE <> 49. There could be between 1-7 products per company.



The attached example file may be a better alternative to view this problem.

View 2 Replies View Related

Macro - Select Multiple Cells By Searching For Specific Text

Nov 8, 2013

I would like to select all cells in column A that begin with the text "SP". Some cells will be contiguous but others will not. For instance in one case, I would like the macro to select cells with the text "SP" which would result in cells A1, A2, A3, A10, A15 being selected. I am working on building a macro that will then do other things to these cells/rows so this is the first step.

The below code will select the first cell with "SP". How would I alter this code to only search Column A and select multiple cells? or totally different code.

Sub test()
Dim r As RangeSet
r = Cells.Find(what:="SP", LookIn:=xlValues, lookat:=xlWhole)
If Not r Is Nothing Then r.Select
End Sub

View 7 Replies View Related

Copy Common Cells And Variable Range From Multiple Worksheets To Single Master Workbook

Apr 2, 2014

Basically, i have a common workbook template that is used by multiple users across the business to request a cost for numerous new products.

Within the template, there is a common section at the top, where specific project information is entered. There is also a table beneath where 1 or many products can be entered, with specific information relating to that product in the same row.

All the submitted requests are uploaded via an email attachment, to a particular sharepoint directory.

What i would like to do in the master workbook is the following:-

1. Open in turn every uploaded workbook within the sharepoint directory and copy the following cells into the master workbook, each in it's own row (or next available), with the data in adjacent cells.... 1st cell to enter data is $B6.

Cells to copy from each sheet:

Common info contained within cells:

Product specific info: $U37, $AD37, $AH37, $DH37, $C37, $O37

Depending on the number of products requested, we need to repeat (loop?) until it finds the next blank row in the table. I have hidden a blank row in the table, so there will always be one!

All of the common information needs to be included for each product specific entry.

For each file, once the upload has been completed, i would like the file to be moved to another "archive" directory.

I have attached the template for information. The master workbook is still in development so can't share currently.

View 12 Replies View Related

Select Rows Using A Variable

Oct 15, 2009

I am trying to select rows that contain text using a variable counting number of rows so rNumb = count number of rows

The Problem

rNumb won't work. What is the proper syntax?

View 2 Replies View Related

Select Worksheet Variable

Jan 30, 2012

I am trying to run some code when a worksheet is selected.

I'm doing this using a macro currently (code below), but this requires that i use a quick menu button and i would like to make it a form button and assign a macro to it (so i can distribute the file without everyone having to create a menu button).

I would like to replace (or modify) the code below to select any sheet other than the ones named "a" and "b".

Sub ImportAlarms()
Dim thisSheet As Worksheet
Dim targetSheet As Worksheet

On Error GoTo failed

Set thisSheet = Application.ActiveSheet
Set targetSheet = Sheets(TARGET_SHEET)

[Code] .......

View 2 Replies View Related

VB To Select Variable Range

Mar 24, 2012

Basically I need a bit of VB to find the last cell in column F with text in it (is it End(xlUp)??) and then apply full borders from that cell up to cell Q5. A test macro tells me the border bit is as follows, so just need defining the range.

Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0

[Code] ......

View 2 Replies View Related

Select Variable Range

Jul 10, 2007

I know how to do Range("A" & I).Select, but how about if I want columns A thru E instead?

View 7 Replies View Related

Select Range With Row Variable

Dec 11, 2007

I am doing is setting a variable called eof to the number of rows (with text) and i just want to select columns A1 - G1 and the eof range!

Dim eof As Integer
With Sheets("Coverage Count (%)")
eof = .Range("G65536").End(xlUp).Row
'crashes on the .select
.Range("A1:G1" & eof).Select
Selection.Sort Key1:=Range("G2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
End With

I've done this before and I could have sworn this worked...but i must be missing something.

View 5 Replies View Related

Select Row Using Variable Row Number

Apr 17, 2008

I don't know how to concatenate a string within the Rows function. I want to be able to vary the row number with a variable, but I don't know how to construct the string, especially given that one of the delimiters within the function is ".

View 3 Replies View Related

Counting Duplicate Cells In Multiple Columns

Mar 10, 2009

I'm on Excel 2003 and have a sheet to track people who have read my emails. I want to know the answers to the questions below. I've included a fake sample to show what I'm looking at. The number of cells in each column is much higher and not the same per column. I've tried variations of MATCH, VLOOKUP, SUMPRODUCT, etc. but haven't found a good way to set up a formula.....

View 6 Replies View Related

Sort Columns With Multiple Values In Cells

Oct 23, 2009

My columns are labeled A B C D etc... If the product I am creating the table for falls into one of those categories I place a 1 in the cell. For instance, ProductA falls into the A and B categories, so column A will get a 1 and column B will get a 1. This is so I can sort all of category A's Products etc...

I am looking for a formula to put in a column that would Say what categories ProductA falls into. ie Since ProductA falls into the A and B catergories but not the C and D catergories, This final column would say something like AB, or A,B or something.

Alternatively, I could make a single column entiltled 'categories' and put something like 'A B' in ProductA's column. In this case I would need a way to sort all A's or sort all B's and not just sort all 'A B'

View 9 Replies View Related

Copyrights 2005-15, All rights reserved