CluelessAboutExcel
New Member
- Joined
- Dec 6, 2021
- Messages
- 5
- Office Version
- 2016
- Platform
- Windows
Hi,
Sorry for two posts about the same thing, won't let me delete the first one. I want to create a VBA code so that I can look up the string "Category 1" and use it as a reference to add a certain number of columns based on another cells value. The new cell values are to have the headings "Category 2", "Category 3", etc.
Currently, I have used the .Find function to locate "Category 1" and then offset columns from there using the .find as a range (see below). However, when I run the macro nothing changes to my spreadsheet. I was wondering whether anybody could spot what is happening here!
Any help would be much appreciated.
See the code below:
Sorry for two posts about the same thing, won't let me delete the first one. I want to create a VBA code so that I can look up the string "Category 1" and use it as a reference to add a certain number of columns based on another cells value. The new cell values are to have the headings "Category 2", "Category 3", etc.
Currently, I have used the .Find function to locate "Category 1" and then offset columns from there using the .find as a range (see below). However, when I run the macro nothing changes to my spreadsheet. I was wondering whether anybody could spot what is happening here!
Any help would be much appreciated.
See the code below:
VBA Code:
Sub Add_Column()
Dim aCount As Integer
Dim a As Integer
Dim c As Range
With Worksheets(3)
aCount = .Range("B12").value
set c = .Cells.Find("Category 1", LookIn:=xlvalues)
For a = 1 To aCount - 1
c.Offset(0, 1).Insert Shift := xlToRight
.Range("G15").Value = "Category" & Str(aCount - a + 1)
Next a
End With
End Sub