+ Reply to Thread
Results 1 to 6 of 6

Absolute cell referencing

  1. #1
    Registered User
    Join Date
    03-24-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Absolute cell referencing

    Hi

    Please kindly assist with my question below.

    I am writing a code to merge cells together; I want the heading of my dataset to be fixed and to appear in all mergers. The table below (and document attached) might give an idea of what I am trying to achieve.

    A B C
    1 Like Dislike Advice
    2 The environment Weather Improve service
    3 Nothing Everything Not applicable





    Merger 1: - Merging rows A:A with B:B

    A1 & A2 & B1 & B2 & C1 & C2

    (Like The environment Dislike Weather Advice Improve service)



    Merger 1: Merging rows A:A with C:C

    A1 & A3 & B1 & B3 & C1 & C3

    (Like Nothing Dislike Everything Advice Not applicable)


    I have already written a code to merge cells but I can not figure how to make row A:A fixed/absolute.

    Regards


    Phresh10
    Attached Files Attached Files

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Absolute cell referencing

    Why, oh why put an Excel table into a Word doc and then post the Word doc instead of posting the Excel file?

    And, if you already have written code that you need advice for, it might be a good idea to post that code as well.

  3. #3
    Registered User
    Join Date
    03-24-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Absolute cell referencing

    Hi

    Thanks for getting back and also for your advise. I have attached an excel spreadsheet with the VBA code I wrote.


    Regards
    Attached Files Attached Files

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Absolute cell referencing

    I've opened your file and stepped through your macro.

    you
    - insert a new column D
    - concatenate the titles in row 1 with the entries in the current row and place the result in column D
    - then you cut a bunch of empty cells and paste it over some other empty cells
    - then you duplicate the current row several times

    What do you want to achieve?

    The concatenation of the title with the current row can be done by a worksheet formula, no VBA required. Just insert a new column D and put this formula into D2 and copy down

    =$E$1&"-"&E2&"-"&$F$1&"-"&F2&"-"&$G$1&"-"&G2

    Double click the line between the column headers of columns D and E to adjust the column width to suit the content.

    So, what is it that I'm not getting?

  5. #5
    Registered User
    Join Date
    03-24-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Absolute cell referencing

    Hi

    Thanks for looking at my question.

    I was given rough spreadsheet that has to be reformatted in many ways before it can be fed it into the system.

    I have been able to write 2 codes that will reformat the first row of the spreadsheet, and also I have added a bit of loop. The number of row in the spreadsheet is not fixed.


    Code 1

    Sub FormatCells()

    Set ws = Sheets("Sheet1")

    Dim string1, string2, string3, string4, string5, string6 As String

    Columns("D:D").Select
    Selection.Insert Shift:=xlToRight

    DataRow = 2

    Do While ws.Range("A" & DataRow) <> ""

    'make D2 active cell
    Application.Goto Range("D" & DataRow)

    string1 = ActiveCell.Offset(-1, 1)
    string2 = ActiveCell.Offset(0, 1)
    string3 = ActiveCell.Offset(-1, 2)
    string4 = ActiveCell.Offset(0, 2)
    string5 = ActiveCell.Offset(-1, 3)
    string6 = ActiveCell.Offset(0, 3)
    ActiveCell.Value = string1 & "-" & string2 & "-" & string3 & "-" & string4 & "-" & string5 & "-" & string6

    DataRow = DataRow + 1

    Loop

    End Sub

    Sub Insert()

    Rows("3:3").Select
    Selection.Insert Shift:=xlDown
    Selection.Insert Shift:=xlDown
    Selection.Insert Shift:=xlDown
    Selection.Insert Shift:=xlDown

    Range("m2:q2").Cut Range("H3:l3")
    Range("r2:v2").Cut Range("h4:l4")
    Range("w2:aa2").Cut Range("h5:l5")
    Range("Ab2:Af2").Cut Range("h6:l6")
    Application.CutCopyMode = False

    Range("A2:D2").Select
    Selection.AutoFill Destination:=Range("A2:D6"), Type:=xlFillCopy
    Range("A2:D6").Select
    Columns("D:D").EntireColumn.AutoFit
    Rows("6:6").EntireRow.AutoFit


    End Sub


    …………………………………………………………………………………………

    Code 2

    Sub FormatCells()

    Set ws = Sheets("Sheet1")

    Dim string1, string2, string3, string4, string5, string6 As String

    Columns("D:D").Select
    Selection.Insert Shift:=xlToRight

    DataRow = 2

    Do While ws.Range("A" & DataRow) <> ""

    'make D2 active cell
    Application.Goto Range("D" & DataRow)

    string1 = ActiveCell.Offset(-1, 1)
    string2 = ActiveCell.Offset(0, 1)
    string3 = ActiveCell.Offset(-1, 2)
    string4 = ActiveCell.Offset(0, 2)
    string5 = ActiveCell.Offset(-1, 3)
    string6 = ActiveCell.Offset(0, 3)


    ActiveCell.FormulaR1C1 = "=R1C5&RC[1]&R1C6&RC[2]&R1C7&RC[3]"
    Range("D2").Select
    Selection.AutoFill Destination:=Range("D2:D4"), Type:=xlFillDefault
    Range("D2:D4").Select




    DataRow = DataRow + 1

    Loop

    End Sub

    Sub Insert()

    Rows("3:3").Select
    Selection.Insert Shift:=xlDown
    Selection.Insert Shift:=xlDown
    Selection.Insert Shift:=xlDown
    Selection.Insert Shift:=xlDown

    Range("m2:q2").Cut Range("H3:l3")
    Range("r2:v2").Cut Range("h4:l4")
    Range("w2:aa2").Cut Range("h5:l5")
    Range("Ab2:Af2").Cut Range("h6:l6")
    Application.CutCopyMode = False

    Range("A2:D2").Select
    Selection.AutoFill Destination:=Range("A2:D6"), Type:=xlFillCopy
    Range("A2:D6").Select
    Columns("D:D").EntireColumn.AutoFit
    Rows("6:6").EntireRow.AutoFit


    End Sub

    Regards

  6. #6
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Absolute cell referencing

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1