Select Columns By Number
Sep 27, 2007an equivalent to the code
rows("8:10").select
for columns. I don't want to use the A, B notation but rather, column numbers.
an equivalent to the code
rows("8:10").select
for columns. I don't want to use the A, B notation but rather, column numbers.
I want to select a number of columns. I know the column indexes.
I want to use something like (Doesn't work):
[Code] ......
Instead of (Works):
[Code] ....
Rows can be selected according to:
[Code] ....
I have written this code that works. But there must be an easier way:
[Code] ....
I have an input box which asks the user to select a row that they wish to delete.
What I need to do is take the row number that has been selected and delete cells B:K and move the below cells up.
I have a multiselect listbox with values that gets populated from a sql statement, and I would like to get is the first or second index from the selected item. I know how to get the listindex from a combobox by using:
VB:
cbnumber.List(.ListIndex, 0)
How can I loop through and get the 1st index number for the selected items only from the listbox? I want to pass this index number to another sql statement.
[Code] ......
How to create a formula in cell M2 that looks at the second row of numbers (0 and 500s) and tells me the rightmost value that is greater than zero. In this example it would return 12.
Second Question: Is there a way to return any counted value, for example the second-to-last number that is over 0?
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)
columnsFound.select
Selection delete
Next i
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 RelatedI'm in the midst of preparing a Year-To-Date (YTD) simple financial report in MS Excel.
Firstly:
I allow user to enter a number in cell A2.
Secondly:
Cells from A4 - L4 are linked from Sheet1. Cell M4 will give sum of A4:L4. Users are not allowed to change data in cells from A4 - L4. Users are only required to enter a number between 1 to 12 in cell A2. Upon update cell A2, the VBA shall sum the number of columns as entered in cell A2.
For example, if user enter 3 in cell A2 then cell M4 must give sum of A4:C4. If user enter 8 in cell A2 then cell M4 must give sum of A4:H4.
I have a competition in bowls format where mats are selected each round so that players do not play on the same mat twice. I was hoping to find through search, where the number selected was never repeated not so far.
I have 32 mats to chose from in one comp, but others can vary from 4 to 24. how to start via vba or formula would be welcome.
if 2 players have played on mats 2,4,8,6 and 12,14,16,18 can a formula check the numbers used and select one that has not been used so far?
I work on a daily basis with spreadsheets in excel. The number of columns is the same, but every single spreadsheet has a different number of rows. I recorded this macro in a table with 1196 rows and I would like to use this macro also in other tables with a different number of rows.
Sub City2()
'
' City2 Macro
'
'
Selection.Copy
Cells.Replace What:="POMPANO", Replacement:="Pompano Beach",
[Code].......
I plucked a macro off an old post from here (as I always do), but I'm having trouble tweaking it.
VB:
Sub completedtest()
Dim c As Range
Dim rngG As Range
For Each c In Intersect(ActiveSheet.UsedRange, Columns("i"))
[Code] ....
As it currently stands, the macro selects the entire row of rows containing the letter Y in column I. All I need to change is, I want to simply select columns B through I, rather than the entire row.
I have a large spreadsheet of species activity data and want to separate information from two columns to create a bar chart of when a certain species is active over a 24-hour period. There are duplicates of each species in one column and a unique corresponding time of activity for that species in another, something like the following:
Species A 23:01
Species B 07:09
Species C 13:45
Species D 08:30
Species A 01:55
Species A 22:07
Species C 15:29
What formula can I enter that only selects Species A and their corresponding times that I can copy into a new spreadsheet?
I would like to somehow select and print the used columns in my pivot table.
I currently have a code that prints TableRange2 but this also includes blank pivot tables columns which are not in use.
Please see attached.
What I would like to do is for each column within range("a1").currentregion that has dates, select the blanks in those columns and put the date 1/1/1900.
The result is in the Result sheet.
I know how to do a standard loop through columns but I'm not sure how to do this for just the current region and just for those columns with dates.
I need to select all data in columns A:F but the number of row containing data is variable. I need to select only the rows with data.
View 7 Replies View RelatedMy issue is I want to use a for loop to go through a spreadsheet. Within the for loop if a certain condition is true I want it to select all columns from A to AW and merge them together.
Example of what I have so far:
Sub MergeHeaders
dim i as Intger, LastRow as Integer
LastRow = Cells(Rows.Count, "CP").End(xlUp).Row
For i = 1 to LastRow
'Check if the leading character is a letter, not number
If Asc(Cells(i, "AP")) > 64 Then
'I want select from A to AW only for current row i, then merge
end If
next i
end sub
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
I have a CSV file which contains a list of records about offices. This CSV file is generated from another program.
I read the CSV file with VBA, a SELECT * SQL statement which puts the elements into an Office Object and adds the offices to a collection.
For some reason, when one of the Telephone numbers is read it is being identified as a Null value. If I manually open the CSV file and change it to a different number e.g. 12345 and try re-read the CSV file with SQL VBA the number gets read fine. Every other element in the CSV file reads fine except for this. The number itself is 7736786460.
Attached is the small snippets of code to read the CSV file which is fairly straightforward.
Code:
Sub LoadUnits()
Dim oRs As Recordset
Set oFSObj = CreateObject("SCRIPTING.FILESYSTEMOBJECT")
'Open an ADO connection to the folder specified
Set oConn = CreateObject("ADODB.CONNECTION")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFilePath & ";" & _
[code]...
I need a macro that will select a random number between 1 and 6. ie select the number of a dice. It needs to input 1 random value into one cell and another random value into another. Like the dice values of a monopoly game.
View 9 Replies View RelatedI 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 RelatedI am currently setting up a userform where one of the options is for an error code (chosen from a listbox) but the user has to be able to select multiple codes. I have the below working if it is NOT multi select, works a dream and goes in the right column.
VB:
If ListBox2.Text = "A1" Then
LastRow.Offset(1, 20).Value = "x"
ElseIf ListBox2.Text = "A2" Then
LastRow.Offset(1, 21).Value = "x"
But as soon as I set it to mutliselect and choose say A1 and A2 neither one writes, I imagine because Listbox2.text is now A1,A2 and not just one or the other.
I am working on a =transpose function. Pretty simple right? Well now I am trying to have it SKIP/SELECT certain columns.
I have =transpose("date!B1:T1"), but now I want to "Select A,B,D,E,F"
=TRANSPOSE(INDIRECT("date!B1:T1"),"select A,B,D,E,F,G,H,P,Q,R,S,T")
I am trying to find a formula that will look at the figures in four columns and then select the lowest for the calculation.
Basically what I am doing is getting venders prices and placing them in the column. The cheapest is then selected.
Showing which vender is used would be a bonus.
I have below a code that is selecting from A11 down as far as there is data and across a certain number of columns then sets a print area.
Currently the columns go A, B, JW, JX, JY, JZ, KA, KB as C through to JV are hidden. I have tried to offset the columns by 7 to see if it will select A-KB but it is selecting cells that are hidden and only selecting A-G. I need it to go past the hidden columns. Here is the code:
[Code] ......
Could I also get a code to go from A10 and move over to KB and create a range from there e.g. KB-KJ and last row from there?
I need a macro to start at cell A11 and select across 10 columns and down to the Lastrow (last row with any data).
There are hidden columns after column D so it CANNOT have any columns hardcoded except for column A.
This selection then needs to be set as a single print area to print out on 1 page. I have already set Rows 1-10 as a title area to print at the top of each page.
Code i currently have is:
[Code] .......
I just need it to now go across 10 visible columns and set as a single print area.
so I have been googling to figure out how to write a macro that will select every other column on my workbook. All that keeps coming up is conditional formatting, which I do not want. I am not trying to highlight the columns in alternating colors, I just want to select them.
I am starting at column F and I would like it to search until the end of the columns and select every other column ending with the last column with data in it.
I know I could search by a specific row and tell it to find the first blank cell then offset it, but there is no particular row that will always have data in it, so I guess it needs to check by column until it finds the first column without any data in all rows and then offset it.
Anyone know what I am talking about here?
I know it should be fairly simple but I couldn't seem to find any answers anywhere else.
Also, anyone know any good websites that have definitions for some basic macros? I'd love to start learning how to write this stuff on my own.
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:
Columns("G:G").Select
Selection.Find(What:="Total Cash", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
[Code]....
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:
Range("P22:P23,R22:R23,T22:T23,V22:V23,X22:X23").Select
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
I have a macro that allows me to select a range of columns and unhide any that are hidden. I am on the sheet "Employees", but the action happens on the sheet "Enter". I can run this macro when I am on "Employees" and jumps top "Enter" and works exactly as I want it to.
Code:
Sheets("Enter").Select
Columns("B:T").Select
Selection.EntireColumn.Hidden = False
Range("M8") = Sheets("Employees").Range("B5")
Range("I7").Select
But when I try to run it as part of another macro that begins on "Employees", I get "Run-time error '1004': Select method of Range class failed", and Columns("B:T") is highlighted.
I have a large spreadsheet with over 50 columns but usually only need to view a small selection of them. Many colleagues use the sheet and often use the format, hide, column function to hide columns they do not need but then the next user has to unhide them and re-hide others until they are left with the different columns they require.
Is there anyway of creating a menu which allows users to select from a list of all the columns those they wish to display, all the others therefore being hidden.
by what means is it possible to unselect randomly selected areas, rows, columns from all sheets?
View 4 Replies View Related