Can't copy formula? [duplicate] - vba

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"")"

Related

Excel VBA deleting cells that contain certain String Values [duplicate]

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

How to delete rows based on empty cell value in VBA [duplicate]

This question already has answers here:
Code in VBA loops and never ends. How to fix this?
(2 answers)
Closed 5 years ago.
I am trying to delete entire rows based on whether the cell value in the D column is NULL or not. My entire code so far is:
Sub DeleteNULL()
Dim i As Long
For i = 2 To 119713
If IsEmpty(Range("Di")) = True Then
Rows([i]).EntireRow.Delete
Else
If IsEmpty(Range("Di")) = False Then
Next i
End If
End Sub
I keep getting compile errors, either If without Else or Next without For, how should I fix this?
Thanks in advance.
A few things:
Placement of a lot of syntax is off.
When adding or deleting rows, you need to loop backwards based on how Excel handles these events.
See code below:
Sub DeleteNULL()
Dim i As Long
For i = 119713 To 2 Step -1
If IsEmpty(Range("D" & i)) Then Rows([i]).EntireRow.Delete
Next i
End Sub

How do you delete multiple columns (possibly non-consecutive) based on an array of number? [duplicate]

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)

Excel VBA (rows reference) [duplicate]

This question already has answers here:
VBA- variable in a range, inside a formula
(2 answers)
Closed 5 years ago.
Hi I am trying to refer to certain rows to do something in VBA.
The code is something like below:
Sub test()
Dim k As Long
k = 9
Rows("5:k").Select
End Sub
I am trying to make my rows dynamic by changing the k value each time. however I am not sure why it cannot select the rows and the code don't work. Any ways to go around this issue? If I substitute k with 9 directly, the code works. But this does not happen.
Am I supposed to select something like rows("5:k(value)).select ?
The problem is that VBA can't recognise the k variable inside the " "
Try something like:
Sub test()
Dim k As Long
k = 9
Rows("5:" & k).Select
End Sub
k is outside the " " so VBA recognises it as a variable and the & tells VBA to concatenate the value of k onto what's inside the " "

Excel VBA Loop through alphabet [duplicate]

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?