+ Reply to Thread
Results 1 to 4 of 4

Help to expand a vba

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-27-2015
    Location
    Norge
    MS-Off Ver
    2019
    Posts
    581

    Help to expand a vba

    Hello

    I have this vba , but now i also want to add column KQ and cell KQ17, but can not figure it out how to add, i did try but failed, the color index is 38

    Sub Sum_Rapmet()
       Dim x As Double
        Dim lr As Long, i As Long
        lr = Range("KA" & Rows.Count).End(xlUp).Row
        x = 0
        For i = 1 To lr
            If Range("KA" & i).Interior.ColorIndex = 4 Then
              x = x + Range("KA" & i).Value2
            End If
        Next i
        Range("KA17") = x
    End Sub

  2. #2
    Forum Contributor
    Join Date
    02-27-2015
    Location
    Norge
    MS-Off Ver
    2019
    Posts
    581

    Re: Help to expand a vba

    Hello

    It works like this but i know it is not right written, try to learn

    Private Sub CommandButton1_Click()
    'MsgBox "Background " & Selection.Interior.ColorIndex
    'MsgBox "Font Color " & Selection.Font.ColorIndex
        Dim x As Double
        Dim lr As Long, i As Long
        lr = Range("KA" & Rows.Count).End(xlUp).Row
        x = 0
        For i = 1 To lr
            If Range("KA" & i).Interior.ColorIndex = 4 Then
              x = x + Range("KA" & i).Value2
               End If
        Next i
        Range("KA17") = x
           
        lr = Range("KQ" & Rows.Count).End(xlUp).Row
        x = 0
        For i = 1 To lr
            If Range("KQ" & i).Interior.ColorIndex = 38 Then
              x = x + Range("KQ" & i).Value2
               End If
        Next i
        Range("KQ17") = x
    End Sub

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Help to expand a vba

    Sub Sum_Rapmet()
       Dim x As Double, y As Double
        Dim lr As Long, i As Long
        lr = Range("KA" & Rows.Count).End(xlUp).Row
        x = 0
        For i = 1 To lr
            If Range("KA" & i).Interior.ColorIndex = 4 Then x = x + Range("KA" & i).Value2
            If Range("KQ" & i).Interior.ColorIndex = 38 Then y = y + Range("KQ" & i).Value2
        Next i
        Range("KA17") = x
        Range("KQ17") = y
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Forum Contributor
    Join Date
    02-27-2015
    Location
    Norge
    MS-Off Ver
    2019
    Posts
    581

    Re: Help to expand a vba

    Hello

    Nice:-) thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 04-25-2020, 09:46 AM
  2. Replies: 6
    Last Post: 11-13-2018, 04:54 AM
  3. How can I expand 1-5 to 1, 2, 3, 4, 5?
    By hdasmc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-30-2013, 12:50 PM
  4. [SOLVED] Expand IF
    By megadilemma in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-21-2013, 10:23 AM
  5. how to expand 1-5 to 1,2,3,4,5 ?
    By ttik in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-27-2007, 11:36 AM
  6. [SOLVED] Using the balance sheet template, any way to expand?-way to expand
    By RABBITS in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-27-2005, 02:05 PM
  7. How do I expand the Name Box?
    By JohnnyQuick in forum Excel General
    Replies: 4
    Last Post: 07-08-2005, 12:05 PM

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