Consulting

Results 1 to 14 of 14

Thread: Help with the meaning of this code

  1. #1

    Question Help with the meaning of this code

    Cells(1, DELTA).Select
    ActiveCell.EntireColumn.Insert
    Cells(1, DELTA + 1).Select
    ActiveCell.EntireColumn.Insert
    DELTA = DELTA + 2
    Columns(DELTA - 2).ColumnWidth = 5

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    it is a 'modified' recorded macro to insert 2 blank columns starting from the column which is given by the variable DELTA and to set column width of that (+2-2 = 0) column.

    procedure would be like:

        Cells(1, DELTA).Resize(, 2).EntireColumn.Insert
        Columns(DELTA).ColumnWidth = 5
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Also, what does this code mean as well especially the "=sum(R43C:R47C)"

    Cells(48, DELTA - 2).FormulaR1C1 = "=sum(R43C:R47C)"

  4. #4
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Hi moiishchiu,

    Quote Originally Posted by moiishchiu View Post
    What does this code mean, especially the "=sum(R43C:R47C)"
    Cells(48, DELTA - 2).FormulaR1C1 = "=sum(R43C:R47C)"
    It means...

    Cells(ROW 48, COLUMN which is set by the variable DELTA).FormulaR1C1 = "SUM(RC43:RC47)"

    Basically, the formula means SUM COLUMN RC ROW 43 to COLUMN RC ROW 47.

    I hope this helps!
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  5. #5
    Thanks it helped a lot !

  6. #6
    I'm a newbie and I was tasked to improve on this current program in excel, I need all the help I can get, what does this code means too haha

    InvoiceDate = Sheets("tracking").Rows(1).Find(What:=strSearch, LookIn:=xlValues, lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, searchformat:=False).Column

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    It looks in row 1 of the sheet called "tracking" for whatever's in strSearch and comes back with the column number that it finds it in.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  8. #8
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Quote Originally Posted by PAB View Post
    Basically, the formula means SUM COLUMN RC ROW 43 to COLUMN RC ROW 47.
    Actually, it's sum the current row, from columns 43 to 47. It's an R1C1 formula, not A1.
    Be as you wish to seem

  9. #9
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by Aflatoon View Post
    Actually, it's sum the current row, from columns 43 to 47. It's an R1C1 formula, not A1.
    !!??
    Do check this by putting it into a sub!
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  10. #10
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Apologies - my comment was based on the code in PAB's post, which says:
    Cells(ROW 48, COLUMN which is set by the variable DELTA).FormulaR1C1 = "SUM(RC43:RC47)"
    The original code actually refers of course to rows 43 to 47 of the current column.
    Be as you wish to seem

  11. #11
    Quote Originally Posted by p45cal View Post
    It looks in row 1 of the sheet called "tracking" for whatever's in strSearch and comes back with the column number that it finds it in.
    Thanks !

  12. #12
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Glad we could help, thanks for the feedback.
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  13. #13
    Hi, im just experimenting now, so why does my below code not work, I want it to add up all the numbers in column 7. When I debugged it it says type mismatch on this line TotalSum = TotalSum + Cells(counter2, 7)

    Sub TotalSumFile()
    Dim TotalSum As Integer
    Dim counter2 As Integer
    Dim lengthoflist As Long

    lengthoflist = Sheets("RawData").UsedRange.Rows.Count
    For counter2 = 1 To lengthoflist
    If Cells(counter2, 7) <> 0 Then
    TotalSum = TotalSum + Cells(counter2, 7)
    End If
    Range("m15") = TotalSum
    Next counter2
    End Sub

  14. #14
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Whatever's in Cells(counter2, 7) is not a whole number (it could be text, or a number with decimals?)
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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