Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50199

Range finding, Vlookup help

$
0
0
Below is my complete code. There are a few questions I have reagrding a few things and I'm hoping you guys/gals would be able to guide me in the right direction

Code:

Sub RepColums()
'Application.ScreenUpdating = False
With ActiveSheet
    Columns("P:P").Select
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("P2").Select
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-1],[ROSTER.xlsm]Sheet1!R1C1:R45C2,2,FALSE)" ' 
    Selection.AutoFill Destination:=Range("P2:P200"), Type:=xlFillDefault    '
    Range("P2:P96").Select
    ActiveWindow.SmallScroll Down:=-96
    ActiveWindow.Zoom = 115
    Selection.Copy
    ActiveWindow.SmallScroll Down:=-96
    Range("O2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("P:P").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft





'deleting unused columns and rearranging them for DPA
Union(Columns(1), Columns(9), Columns(22), Columns(30), Columns(34), Columns(35), Columns(36), Columns(37), Columns(38)).Delete
        'Excel.activecells.Delete

 
    Excel.Columns(2).Cut
    Excel.Columns(1).Insert
    Excel.Columns(3).Cut
    Excel.Columns(2).Insert
    Excel.Columns(4).Cut
    Excel.Columns(3).Insert
    Excel.Columns(25).Cut
    Excel.Columns(8).Insert
    Excel.Columns(26).Cut
    Excel.Columns(15).Insert
    Excel.Columns(24).Cut
    Excel.Columns(22).Insert
    Excel.Columns(25).Cut
    Excel.Columns(23).Insert
    Excel.Columns(29).Cut
    Excel.Columns(27).Insert
    Union(Columns(28), Columns(29), Columns(21), Columns(22), Columns(24)).Delete

'sorting by Auditor ID
    Columns("A:AA").Sort key1:=Range("N2"), _
      order1:=xlAscending, Header:=xlYes


'MsgBox "OK"




End With
Range("A1").Select
    Selection.Subtotal GroupBy:=14, Function:=xlSum, TotalList:=Array(16, 17, _
    18, 19, 24), Replace:=True, PageBreaks:=False, SummaryBelowData:=True

'Columns("P:P").NumberFormat = "Currency"

'Rows(1).Select
Excel.Cells(1, 14).Value = "AUD"
Excel.Cells(1, 15).Value = "Res"
Excel.Cells(1, 2).Value = "I"
Excel.Cells(1, 3).Value = "DOA"
Excel.Cells(1, 11).Value = "RGC"
Columns("P:P").Select
    Selection.Style = "Comma"
Rows(1).WrapText = True
Excel.Range("A:X").Columns.AutoFit

Range("A1").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.249946592608417
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.249946592608417
        .Weight = xlThin
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.249946592608417
        .Weight = xlThin
    End With
    Range("A1").Select
   

End Sub


#1 What if my ROSTER changes. Is there a dynamic way to find the range of the 2 columns in the roster file and translate that to the formula I'm adding to each cell? I open the roster file before i run this macro.

Code:

ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-1],[ROSTER.xlsm]Sheet1!R1C1:R45C2,2,FALSE)" '


#2 What I'm doing here is adding a column in my data, pasting the vlookup formula then copying the results of the vlookup and replacing the value that i looked up.

But my reports change length(#rows) and all my row values are hard coded, I need to make them dynamic because, well, just it's the only way it'll work. I think I need to do a row count, except for the header row, then add row count result to a variable, and use that variable in as the numbers? How is that done?

Code:

ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-1],[ROSTER.xlsm]Sheet1!R1C1:R45C2,2,FALSE)" ' 
    Selection.AutoFill Destination:=Range("P2:P200"), Type:=xlFillDefault    '
    Range("P2:P96").Select
    ActiveWindow.SmallScroll Down:=-96
    ActiveWindow.Zoom = 115
    Selection.Copy
    ActiveWindow.SmallScroll Down:=-96
    Range("O2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("P:P").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft


#3 Why is this formatting the entire workbook, not just to the limits of my data? I run the subtotal function before this, so there are rows in column A that have blank cells, because the subtotals are in column N i think.

Code:

Range("A1").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.249946592608417
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.249946592608417
        .Weight = xlThin
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.249946592608417
        .Weight = xlThin
    End With
    Range("A1").Select


Viewing all articles
Browse latest Browse all 50199

Trending Articles