tomburns1987
New Member
- Joined
- Aug 2, 2013
- Messages
- 2
Hi guys,
I have written some VBA code where i input a nominal code and then the code does what I need it to do.
I have several tabs in this workbook and on each tab there are serveral nominal codes where the data gets pasted underneath.
Currently I use an inputbox and manually type in one code at a time and then move on to the next.
My question is this - Is there a way I can input a list of codes at the start and loop the code until it has gone through each one OR can I get it to work through a list of codes and pick those out to use in the variables inside the code?
(i have to use 2 codes at the moment, first one finds a starting point for a formula copy down)
Code below
Thanks.
I have written some VBA code where i input a nominal code and then the code does what I need it to do.
I have several tabs in this workbook and on each tab there are serveral nominal codes where the data gets pasted underneath.
Currently I use an inputbox and manually type in one code at a time and then move on to the next.
My question is this - Is there a way I can input a list of codes at the start and loop the code until it has gone through each one OR can I get it to work through a list of codes and pick those out to use in the variables inside the code?
(i have to use 2 codes at the moment, first one finds a starting point for a formula copy down)
Code below
Thanks.
Code:
Sub findactivecell()
Dim Nominal1 As Integer
Nominal1 = InputBox("Please enter Nominal 1", "Nominals", "6200")
Set result = Cells.Find(What:=Nominal1)
result.Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.Offset(0, 11).Select
Call Automate
End Sub
Code:
Sub Automate()
'Dims
Dim Nomcount As Integer
Dim myrange As Range
Dim Nominal1 As Integer
Dim sheetname As String
'Inputs
sheetname = ActiveSheet.Range("A1").Value
Nominal1 = InputBox("Please enter Nominal 1", "Nominals", "6200")
'Sets
Set myrange = Sheets("Dump").Columns(1)
Set result = Sheets(sheetname).Cells.Find(What:=Nominal1)
Set Resultdump = Sheets("Dump").Cells.Find(What:=Nominal1)
Set Rowval = Sheets(sheetname).Range("L5:EX5")
'Variables
Nomcount = Application.WorksheetFunction.CountIf(myrange, Nominal1)
Lastrow = Worksheets("Dump").Cells(Rows.Count, 1).End(xlUp).Row
lastcol = Left(Sheets(sheetname).Range("A3:EX3").Find("Check").Address, 3)
Colcount = ActiveCell.Row
Autofillrange = "L" & Colcount & ":" & lastcol & Colcount
Autofillrange2 = "L" & (Colcount + Nomcount + 1) & ":" & lastcol & (Colcount + Nomcount + 1)
'Actions
Sheets(sheetname).Select
result.Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
ActiveCell.Rows("2:" & Nomcount + 1).EntireRow.Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
result.Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.Offset(0, 11).Select
With ActiveSheet
Range(ActiveCell.Address & ":" & lastcol & Colcount).Select
End With
Selection.AutoFill Destination:=Range(Autofillrange, Autofillrange2), Type:=xlFillDefault
Sheets("Dump").Activate
Range("A2:L" & Lastrow).Select
Selection.AutoFilter
Worksheets("Dump").Range("A1").AutoFilter Field:=1, Criteria1:=Nominal1
Range("A:A").EntireColumn.Hidden = True
Selection.Offset(1, 0).Select
Selection.Copy
Sheets(sheetname).Select
result.Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
ActiveCell.Offset(1).Select
ActiveSheet.Paste
With Range("G:K")
.HorizontalAlignment = xlCenter
.Style = "Comma"
End With
With Range("A:A")
.Borders(xlEdgeRight).LineStyle = xlContinuous
End With
Sheets("Dump").Activate
Range("A:A").EntireColumn.Hidden = False
Sheets("Dump").AutoFilterMode = False
Worksheets(sheetname).Activate
End Sub