Consulting

Results 1 to 5 of 5

Thread: Solved: Copy Cell Values from Non-adjacent columns

  1. #1

    Solved: Copy Cell Values from Non-adjacent columns

    Hello VBA Express Nation!

    I have need for a second pair of eyes, in which I am having difficulty in renaming cells with categories. For example, for all items grouped in ADSL, it is logical that the total sum of the contents within this category would be "Total:ADSL". However, in my code I have only been able to get "Total:" along with the row value of the cell I would like. Below is my code along with an attachment showing the worksheet I am using. I hope someone with eyes less red than I will find where I am going wrong.

    [vba]Sub Ignition()
    Dim EndRow As Long
    Dim InnerRowSkip As Integer
    Dim OuterColumns As Integer
    Dim strCellLocator As Integer
    Dim strCellCategory As String
    Dim strCellIdentifier As String
    With ActiveSheet
    EndRow = .Cells(65536, 1).End(xlUp).Row
    For OuterColumns = 1 To 2
    Select Case OuterColumns

    Case 1
    strCellIdentifier = "Total:"
    Case 2
    strCellIdentifer = "Sub-total:"

    End Select

    For InnerRowSkip = 4 To EndRow
    If Left(.Cells(InnerRowSkip, OuterColumns + 1), 6) = strCellIdentifier _
    Or Left(.Cells(InnerRowSkip, OuterColumns + 1), 10) = strCellIdentifier Then
    strCellLocator = .Cells(InnerRowSkip, OuterColumns).End(xlUp).Row
    strCellCategory = .Range(strCellLocator, OuterColumns).Value
    .Cells(InnerRowSkip, OuterColumns + 1).Value = strCellIdentifier & " " & strCellCategory
    End If
    Next InnerRowSkip

    Next OuterColumns

    InnerRowSkip = 4
    End With
    End Sub

    [/vba]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The worksheet is empty so it shows nothing.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    Copy Cell Values from Non-adjacent Columns

    I'm sorry. I will re-attach again.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I'm getting an error here. change Range to Cells in this line.

    [VBA]
    strCellCategory = .Cells(strCellLocator, OuterColumns).Value
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5

    Copy Cell Values from Non-adjacent columns

    Thanks for the second pair of eyes! What I also noticed is that [VBA]Case 2
    strCellIdentifier = "Sub-total:"[/VBA]

    That is why the second and third columns were not being properly labeled.

    Thanks again mckillop!

    Cheers
    CCSlice

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •