This question already has answers here:
Excel column number from column name
(7 answers)
Function to convert column number to letter?
(28 answers)
Closed 8 years ago.
I currently have a excel file with a couple of columns and many rows, each cell holds information. Currently my macro has a loop within a loop to go through each row and column. The loop for the row is no problem, i just keep increasing the number by a step of 1, but when it comes to the columns i have made my own sub routine. this subroutines changes the numbers in the loop to letter and stores that letter in a variable.
For firstloop = 3 To number
For column = 1 To 3
columnconvert
'some code in here
next
next
and this code is the new subroutine i made:
Sub columnconvert()
Select Case column
Case "1"
columnletter = "Q"
Case "2"
columnletter = "R"
Case "3"
columnletter = "S"
End Select
End Sub
i was wondering, is there an easier way to "CONVERT" the loop number to a letter? could i loop through with letters instead of numbers?
Related
This question already has answers here:
Deleting Duplicate Visible Rows
(2 answers)
Code not deleting every non numeric row
(1 answer)
VBA For loop not exiting
(3 answers)
Delete specific rows from selection in for each loop
(1 answer)
Excel ListObject Table - Remove filtered / hidden rows from ListObject table
(1 answer)
Closed 4 years ago.
I am trying to write a code that goes row by row checking to see if a certain column in that row contains the string values "Pick-Up" or "Pickup", and if it does delete that entire row. The code I currently have runs, and deletes some of the rows containing said values. But not all of them.
I have tried the AutoFilter method, and for my purposes I do not believe that it will work.
Any help would be greatly appreciated. Thanks!
Sub Delete()
Dim x As Long, y As Long
Dim testString As String
y = Worksheets("Data").Range("A1", Range("A1").End(xlDown)).Rows.Count
For x = 2 To y
testString = Worksheets("Data").Cells(x, 27).Value
testString = Trim(testString)
If testString Like "*Pick-Up*" Or testString Like "*Pickup*" Then
Rows(x).EntireRow.Delete
Else
x = x + 1
End If
Next x
End Sub
This question already has answers here:
Find last used cell in Excel VBA
(14 answers)
Closed 5 years ago.
I have a column in excel that I import from a program and it always imports it in this format if these bars represent the cells, | | with trailing spaces and <> to represent a negative numbers. The positive numbers come out like this, | $758.92| also with trailing spaces. The number format is Currency and I want to be able to sum these numbers and not have to go down the column of 100 or 200 cells and change all of them.
I started a macro that I want to iterate over each cell and remove the trailing spaces and replace the <> with () to indicate a negative number and just remove the trailing spaces for the positive numbers.
Sub Macro1()
Dim i As Integer, d As Integer
i = 13
Do Until .Cells(4, i).Value = ""
For d = 4 To 100 *I want the loop to stop at the first empty cell.*
Cells(d, i) = Trim(Cells(d, i))
Cells(d, i) *Replace the < at the beginning and end with ()*
Next d
i = i + 1
Loop
End Sub
Before initiating that first do loop, you can find the last cell of the column if it will be the same each time:
lRow= Range("A" & Rows.Count).End(xlUp).Row 'Replace A with column you want
This will store the last row, and you can replace d = 4 to 100 with:
for d = 4 to lRow
This question already has answers here:
workaround named range character limit
(3 answers)
Closed 5 years ago.
Suppose you have an array of numbers, and they are the column numbers that you would like to delete. A smart idea is to convert them to letters and then concatenate them and delete all the columns, as shown here by #Siddharth Rout. But there is a problem, it seems there is an upper limit of string inside range, so say
str = "AB:AB,CJ:CJ,CZ:CZ,NJ:NJ,NK:NK,NL:NL...",
Len(str)=300, 'Just about 50 columns, not too many indeed, there are 16384 columns in Excel 2010!!!
Chances are you will get an error if you use Range(str).Delete Shift:=xlToLeft, how to solve this problem?
Another option
Option Explicit
Public Sub DeleteColumns()
Dim i As Long, arr As Variant
arr = Split("3-5-7", "-") 'ascending order
Application.ScreenUpdating = False
With Sheet1
For i = UBound(arr) + 1 To LBound(arr) + 1 Step -1
.Cells(Val(arr(i - 1))).EntireColumn.Delete
Next
End With
Application.ScreenUpdating = True
End Sub
(slow for a large number of columns)
This question already has answers here:
Find last used cell in Excel VBA
(14 answers)
Closed 5 years ago.
Hi I am having issues getting to the last column used in my sheet.
I do know that as it stands my last column is 43 and i want it to enter a value at column 44, so then when i search again it will go to column 44 as last column used and then enter a value at 45 and so on and so on. I am using a ref num to find the correct row.
The code I am using is as follows to try get the last column
'find last empty Col in database
LastCol = sou.Cells(2, Columns.count).End(xlToLeft).Column + 1
MsgBox LastCol
'For Loop to cycle through the columns
For x = 2 To LastCol
'If the row value at column 1 = the ref number then continue
If sou.Cells(x, 1).Value = refNum Then
sou.Cells(x, LastCol).Value = Me.commentBox.Text
Exit For
End If
Next
The issue is that for some reason it only goes to column 22. I have tried to use the other ways to get the last column but they have just given me the last column in the whole entire sheet which again is not what I want.
If someone can lend me a hand as I'm a newbie to this it would be greatly appreciated!
To find the last row used, have you tried
lastRow = ActiveSheet.UsedRange.Rows.Count
If that didn't work, please elaborate what went wrong and I can submit more code.
This question already has answers here:
How do I put double quotes in a string in vba?
(5 answers)
Closed 5 years ago.
I can't operate the code without it stating the sub or function is not defined in the formula I'm trying to paste down column v.
Sub SEALANTSCHEDULIZER()
' 1. Unhide All Columns
Columns.EntireColumn.Hidden = False
' 2. Clear All color highlights
ActiveSheet.UsedRange.Interior.ColorIndex = 0
' 3. Drag formulas in all columns down to last row (if necessary) – use column A (ID) as row count
LastRowColumnA = cell(Rows.count, 1).End(xlUp).Row
Range("V2:V" & LastRowColumnA).Formula = "=IF(OR(W2="Yes", AE2="Yes"), "Yes", "No")"
End Sub
You need to double the " around the text strings.
"=IF(OR(W2=""Yes"", AE2=""Yes""), ""Yes"", ""No"")"