I am trying to use macro recorder in Excel to record a macro to fill down a column of cells, however because the fill down each time is a different number of cells it either fills down to short or too long and this seems to be because the macro identifies the cell range and its fixed.
What I need is to auto populate or auto fill down from:
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[1],"" "",RC[2])"
Range("C1").Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:A261")
ActiveCell.Range("A1:A261").Select
Since file is not always 261? How can I place a command to choose/autofill the last column?
Blockquote
Sub WMEHOT_Cleaner()
'
' WMEHOT_Cleaner Macro
'
'
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("L:L").Select
Selection.Cut
Columns("B:B").Select
ActiveSheet.Paste
Columns("C:C").Select
Selection.Cut
Range("O1").Select
ActiveSheet.Paste
Range("C1").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[1],"" "",RC[2])"
Range("C1").Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:A261")
ActiveCell.Range("A1:A261").Select
Range("C1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.End(xlUp).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("D:E").Select
Selection.ClearContents
Range("D1").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[2],"" "",RC[6])"
Range("D1").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[5],""_"",RC[6])"
Range("D1").Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:A261")
ActiveCell.Range("A1:A261").Select
ActiveCell.Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.End(xlUp).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("I:J").Select
Selection.ClearContents
Columns("O:O").Select
Selection.Cut
Columns("E:E").Select
ActiveSheet.Paste
Columns("F:F").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("L:L").Select
Selection.Cut
Columns("J:J").Select
ActiveSheet.Paste
Range("J1").Select
Selection.Copy
Range("L1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A1").Select
ActiveCell.FormulaR1C1 = "=""WMEOnline_""&RC[9]"
Range("A1").Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:A261")
ActiveCell.Range("A1:A261").Select
ActiveCell.Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.End(xlUp).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveCell.Offset(2, 0).Range("A1").Select
Range("O5").Select
Cells.Select
Range("A1").Activate
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
msgclean = MsgBox("Cleaning and Sorting Complete!!" & vbNewLine & "File Ready for LMS." & vbNewLine & "Please SAVE this file as CSV Format", vbInformation + vbOKOnly, "WME HOT Cleaner Template")
End Sub
Use the following code:
Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Formula = "=CONCATENATE(RC[1],"" "",RC[2])"
Replace A if your column is not column A
Use
lr = Cells(Rows.Count, "A").End(xlUp).Row
to find the last row from a column or
Set wks = ActiveWorkbook.Worksheets(sheet)
i = wks.Range("A:A").End(xlDown).Row
j = wks.Cells.End(xlToRight).Column
to find the position of the last cell.
Related
I am trying to copy a range of cells in a single column and transpose them above
as a row.
The problem I am having is to try to increase the Rows(45:45) where each row is being copied, otherwise all of the rows get overwritten.
When I run the macro I get a syntax error on Destination:= Range line
Range("A53:A63").Copy
Range("A52").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
Range("A53:A63").Select
Application.CutCopyMode = False
Selection.EntireRow.Delete
Rows("52:52").Cut
Rows("45:45").Select
Destination:=Range("A" & Rows.Count).End(xlDown).Offset(1, 0)
Selection.Insert
Although I do not really understand what you are trying to do but maybe this helps.
Sub test()
Range("A53:A63").Copy
Range("A52").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
Range("A53:A63").Select
Application.CutCopyMode = False
Selection.ClearContents
Rows("52:52").Copy
Range("A1").End(xlDown).Offset(1, 0).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End Sub
I have a spreadsheet with hundreds of table broken out by WBS, with odd formatting.
Beginning Format
What I want it to look like
I found a solution in which the starting tables are better organized into a summary table with headers at top:
How to "flatten" or "collapse" a 2D Excel table into 1D?
The macro I used works for two tables but uses absolute references to copy and transpose the data. It's very rough, but I've included below to show that I attempted.
The column (HRS, P, etc) and row (AL, Con, IH, etc) headings don't appear to change, so I assume I need something that will find a WBS and grab this information. Another issue is that some of the tables have extra Column headings before the Travel row (see second table in screenshot).
How do I go about writing something that will search for a WBS and record the flattened data, without referencing the specific cells?
Let me know if my question is poorly worded or if more information is needed.
Code from first macro:
Attribute VB_Name = "Module2"
Sub flatten_data()
Attribute flatten_data.VB_ProcData.VB_Invoke_Func = " \n14"
'
' flatten_data Macro
'
'
Range("B1").Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("A1:A42"), Type:=xlFillDefault
Range("A1:A42").Select
ActiveSheet.Previous.Select
Range("F3:K3").Select
Selection.Copy
ActiveSheet.Next.Select
ActiveWindow.SmallScroll Down:=-45
Range("B1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Application.CutCopyMode = False
Selection.Copy
Range("B7").Select
ActiveSheet.Paste
Range("B13").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=6
Range("B19").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=9
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("B19:B42"), Type:=xlFillDefault
Range("B19:B42").Select
ActiveSheet.Previous.Select
Range("C6").Select
Selection.Copy
ActiveSheet.Next.Select
Range("C16").Select
ActiveWindow.SmallScroll Down:=-54
Range("C1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("C1:C6"), Type:=xlFillDefault
Range("C1:C6").Select
Selection.Copy
ActiveSheet.Previous.Select
Range("C7").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("C7:C12").Select
ActiveSheet.Paste
ActiveSheet.Previous.Select
Range("C8").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("C13:C18").Select
ActiveSheet.Paste
ActiveSheet.Previous.Select
Range("C9").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("C19:C24").Select
ActiveSheet.Paste
ActiveSheet.Previous.Select
Range("C10").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("C25:C30").Select
ActiveSheet.Paste
ActiveSheet.Previous.Select
Range("C11").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveWindow.SmallScroll Down:=12
Range("C31:C36").Select
ActiveSheet.Paste
ActiveSheet.Previous.Select
Range("C12").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("C37:C42").Select
ActiveSheet.Paste
ActiveSheet.Previous.Select
Range("F6:K6").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveWindow.SmallScroll Down:=-33
Range("D1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Range("D7").Select
ActiveSheet.Previous.Select
Range("F7:K7").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveSheet.Previous.Select
Range("F8:K8").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("D13").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveSheet.Previous.Select
Range("F9:K9").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("D19").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveSheet.Previous.Select
Range("F10:K10").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("D25").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveWindow.SmallScroll Down:=18
ActiveSheet.Previous.Select
Range("F11:K11").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("D31").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveSheet.Previous.Select
Range("F12:K12").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("D37").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveSheet.Previous.Select
Range("B16").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("A43:A84").Select
ActiveSheet.Paste
Range("B1:B42").Select
Range("B42").Activate
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=24
Range("B43").Select
ActiveSheet.Paste
Range("C1:C42").Select
Range("C42").Activate
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=27
Range("C43").Select
ActiveSheet.Paste
ActiveSheet.Previous.Select
Range("F21:K21").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("D43").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveSheet.Previous.Select
Range("F22:K22").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("D49").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveSheet.Previous.Select
Range("F23:K23").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("D55").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveSheet.Previous.Select
Range("F24:K24").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveWindow.SmallScroll Down:=12
Range("D61").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveSheet.Previous.Select
Range("F25:K25").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("D67").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveWindow.SmallScroll Down:=21
ActiveSheet.Previous.Select
Range("F26:K26").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("D73").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveSheet.Previous.Select
Range("F29:K29").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("D79").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
End Sub
I'm assuming that the tables are all of the same size and relative offset to the WBS keyword. I'm also assuming that the row "Travel" isn't needed in the final output, and the subtotals will be recalculated if needed.
Option Explicit
Sub Flatten_Data()
Dim wb As Workbook
Dim ws As Worksheet
Dim GCell As Range
Dim TableCell As Range
Dim TotalTables As Integer
Dim TableNumber As Integer
Dim TableRow As Integer
Dim TableColumn As Integer
Dim ColumnHeader(6) As String
Dim RowHeader(7) As String
ColumnHeader(1) = "HRS"
ColumnHeader(2) = "P"
ColumnHeader(3) = "OH"
ColumnHeader(4) = "G"
ColumnHeader(5) = "C"
ColumnHeader(6) = "F"
RowHeader(1) = "AL"
RowHeader(2) = "Con"
RowHeader(3) = "IH"
RowHeader(4) = "Mat"
RowHeader(5) = "OD"
RowHeader(6) = "SUB"
RowHeader(7) = "Trav"
Set wb = Workbooks("Book1") ' or whatever sheet holds the source data
Set ws = Worksheets("Sheet1") ' or whatever sheet you want to copy the flattened data to
With wb
With ws
Set GCell = .Range("A:A")
TotalTables = Application.WorksheetFunction.CountIf(GCell, "WBS")
Set GCell = .Cells.Find("WBS", .Cells(1048576, 1)) ' looks for "WBS" and ensures that it finds one in A1 if it exists
For TableNumber = 1 To TotalTables
For TableRow = 1 To 7
For TableColumn = 1 To 6
Worksheets("Sheet2").Cells(TableColumn + (TableRow - 1) * 6 + (TableNumber - 1) * 42, 4) = GCell.Offset(4 + TableRow, 4 + TableColumn).Value
Worksheets("Sheet2").Cells(TableColumn + (TableRow - 1) * 6 + (TableNumber - 1) * 42, 3) = RowHeader(TableRow)
Worksheets("Sheet2").Cells(TableColumn + (TableRow - 1) * 6 + (TableNumber - 1) * 42, 2) = ColumnHeader(TableColumn)
Worksheets("Sheet2").Cells(TableColumn + (TableRow - 1) * 6 + (TableNumber - 1) * 42, 1) = "1." & TableNumber
Next TableColumn
Next TableRow
Set GCell = .Cells.FindNext(GCell)
Next TableNumber
End With
End With
End Sub
I'll leave it to you to ensure that the table numbers are correct.
And I'd avoid 'Select' like the plague for this sort of thing, it'll only slow down the code.
hiya all thanks in advance for any help
my goal is to transfer all the data from a discount grid and converting it to a list format
i have the grid as the source sheet and i am creating a new sheet ready for import to a new system which needs it laying out in a list format
name(A)-type(B)-(C)-discount(D)
(column c must be blank)
1 i need to take the company name and copy it 17 more times (for each product type)
2 i then take the product types from the top and transpose into next column
3 i then miss out 1 column then copy and transpose in the discount values in the next column
this then needs to be repeated until it finds a blank on the source page
i have constructed a basic macro but it means ill have to redo for each customer which currently stands at 939 customers (nightmare) is there a set of commands i can put into my macro to achive this ?
here is a copy of my current code
Workbooks.Add
ChDir "F:\darren t"
ActiveWorkbook.SaveAs Filename:="F:\darren t\Ready Discount Grid.xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Windows("Tools for ball.xlsm").Activate
Workbooks.Open Filename:="F:\darren t\DISCOUNTS GRID M2M.xlsx"
Cells.Select
Selection.ClearFormats
Cells.EntireColumn.AutoFit
Range("B2:S936").Select
Range("S936").Activate
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "0"
Range("A2").Select
'Create grid names
Windows("Ready Discount Grid.xlsx").Activate
Application.CutCopyMode = False
Range("A1").Select
ActiveCell.FormulaR1C1 = "Customer Account Code"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Blind Type Code"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Option Stock Code"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Discount %"
Cells.Select
Cells.EntireColumn.AutoFit
' paste names (repeat 938 times)
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("A2").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("A2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("A2:A19"), Type:=xlFillDefault
Range("A2:A19").Select
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("A3").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("A20").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("A20:A37"), Type:=xlFillDefault
Range("A20:A37").Select
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("A4").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("A38").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("A38:A57"), Type:=xlFillDefault
Range("A38:A57").Select
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("A5").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("A58").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("A58:A73"), Type:=xlFillDefault
Range("A58:A73").Select
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("A6").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("A74").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("A74:A91"), Type:=xlFillDefault
Range("A74:A91").Select
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("A7").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("A92").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("A92:A109"), Type:=xlFillDefault
Range("A92:A109").Select
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("A8").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("A110").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("A110:A127"), Type:=xlFillDefault
Range("A110:A127").Select
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("A9").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("A128").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("A128:a145"), Type:=xlFillDefault
Range("A128:A145").Select
' paste types (repeat 938 times)
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("B1:W1").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Application.CutCopyMode = False
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("B1:W1").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("B20").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Application.CutCopyMode = False
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("B1:W1").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("B38").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Application.CutCopyMode = False
'paste discount values (repeat 938 times)
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("B2:S2").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("D2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("B3:S3").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("D20").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Windows("DISCOUNTS GRID M2M.xlsx").Activate
Range("B4:S4").Select
Selection.Copy
Windows("Ready Discount Grid.xlsx").Activate
Range("D38").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
'Put rest of the data below here
End Sub
there must be a much more efficent way to do this
any help would be amazing
This could help
Do while activecell.value <> ""
'Code that must repeat
Activecell.Offset(1,0).Active 'Moves the active cell
Loop
activecell.value
Evaluates the activecell value, which one in the case that it's empty will stop
I have recorded a macro to make changes to a sheet. Basically it makes a few changes such as add a column move two columns over and so forth. The thing that I am confused with is adding a small code to give me a count of the total DL and IDL in the MO REAL column L separately and putting the total count on another sheet in the same workbook "Resultados" in cells B17 and C17... Any ideas on how this can be accomplished? Here is the recorded code:
Option Explicit
Sub DefineDL_IDL()
Dim wbTHMacro As Workbook, wsRegulares As Worksheet, wsRegularesDemitidos As Worksheet, wsTempActivos As Worksheet, _
wsTempJA As Worksheet, wsTempFit As Worksheet, wsTempDemitidos As Worksheet, wsPS As Worksheet, wsResultados As Worksheet, _
wsDLList As Worksheet, wssheet As Worksheet
Sheets("Regulares").Select
Columns("J:J").Select
Selection.Insert Shift:=xlToRight
Range("J1").Select
ActiveCell.FormulaR1C1 = "MO REAL"
Columns("K:K").Select
Selection.Cut
Columns("I:I").Select
Selection.Insert Shift:=xlToRight
Columns("Q:Q").Select
Selection.Cut
Columns("I:I").Select
Selection.Insert Shift:=xlToRight
Range("K1").Select
Selection.AutoFilter
ActiveSheet.Range("A:Z").AutoFilter Field:=11, Criteria1:= _
"INATIVE"
Rows("5:5").Select
Range("F5").Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("A:Z").AutoFilter Field:=11
Range("L2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-3],'DL List'!RC[-11]:R[32]C[-10],2,0)"
Range("L2").Select
Selection.AutoFill Destination:=Range("L2:L5890")
Range("L2:L5890").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("L2").Select
ActiveSheet.Range("A:Z").AutoFilter Field:=11, Criteria1:="DL"
ActiveSheet.Range("A:Z").AutoFilter Field:=12, Criteria1:="#N/A"
Range("L23").Select
ActiveCell.FormulaR1C1 = "DL"
Range("L23").Select
Selection.Copy
Range("L25").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Range("A:Z").AutoFilter Field:=12
Range("L4").Select
ActiveSheet.Range("A:Z").AutoFilter Field:=11, Criteria1:=Array( _
"G&A", "MOH", "IDL", "Other MOH"), Operator:=xlFilterValues
ActiveSheet.Range("A:Z").AutoFilter Field:=12, Criteria1:="#N/A"
Range("L7").Select
ActiveCell.FormulaR1C1 = "IDL"
Range("L7").Select
Selection.Copy
Range("L15").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
ActiveSheet.Paste
Application.CutCopyMode = False
Range("L7").Select
ActiveWorkbook.Worksheets("Regulares").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Regulares").AutoFilter.Sort.SortFields.Add Key:= _
Range("K1:K5890"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption _
:=xlSortNormal
ActiveSheet.Range("A:Z").AutoFilter Field:=12
Range("K2").Select
ActiveSheet.Range("A:Z").AutoFilter Field:=11
Range("G2").Select
ActiveCell.FormulaR1C1 = "1"
Range("G2").Select
Selection.Copy
Range("J2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _
SkipBlanks:=False, Transpose:=False
Range("J2").Select
Application.CutCopyMode = False
End Sub
If you are counting the times "DL" and "IDL" occur...
'Count DL and IDL
count_DL = Application.WorksheetFunction.CountIf(ActiveSheet.Range("L:L"), "DL")
count_IDL = Application.WorksheetFunction.CountIf(ActiveSheet.Range("L:L"), "IDL")
'Paste results in Resultados sheet
Worksheets("Resultados").Range("B17") = count_DL
Worksheets("Resultados").Range("C17") = count_IDL
Your question is a little confusing without understanding a broader picture of what you're doing. All you need to do to get a count and put it in another sheet is:
Sheets("AnotherSheet").Range("B13") = Application.WorksheetFunction.CountA(Columns("G:G"))
I need to write a Loop to run the following lines until the third line finds the cell it is selecting to be empty.
I would normally include my code for the loop to be corrected / critiqued but after searching all morning I can't find an example of do while loop that doesn't count to keep moving.
Can someone point me in the right direction with a link or two?
Sheets("Sheet1").Select
Selection.Offset(0, 3).Select
Selection.Offset(1, 0).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection(1, 3)).Select
Selection.Copy
Sheets("Output").Select
Selection.End(xlDown).Select
Selection.Offset(1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Include Fund name
Sheets("Sheet1").Select
Selection.End(xlUp).Select
Selection.Copy
Sheets("Output").Select
Range("B2").Select
Selection.End(xlDown).Select
Selection.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.Offset(0, 1).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Offset(0, -1).Select
Selection.FillDown
I can't find an example of do while loop that doesn't count to keep moving.
You didn't look very hard, then. All Do or While loops should have a terminator, or an Exit statement, otherwise they will crash the application in an infinite loop.
Try:
Do Until Sheets("Sheet1").Selection.Offset(1, 0).Value = vbNullString
'// YOUR CODE HERE //
Loop
Or:
Do
If Sheets("Sheet1").Selection.Offset(1, 0).Value = vbNullString Then Exit Do
'// YOUR CODE HERE //
Loop