+ Reply to Thread
Results 1 to 3 of 3

Start Macro in certain row

Hybrid View

  1. #1
    Registered User
    Join Date
    08-25-2018
    Location
    wisconsin
    MS-Off Ver
    2013
    Posts
    28

    Start Macro in certain row

    Hello,

    I am new to VBA and I am attempting to write a macro that will subtract 2 cells and record the info in a 3rd cell. I would need the formula to continue in each row until the last line of info. It starts J2 - H3, then on the next row would be J3 - H4 and so on.This would repeat on multiple sheets within a workbook. The big problem is there is different formula in J2 that must remain untouched. I came up with the macro below but it still starts in J2 and overwrites the formula there. I just need this process to start on J3. Any help would be greatly appreciated.

    Sub ONHAND2()
    Dim ws As Worksheet
    Dim Lastrow As Long
    With ActiveSheet
    For Each ws In ActiveWorkbook.Worksheets
    Sheets.Select
    ws.Activate
    LastRowColumnH = Cells(Rows.Count, 1).End(xlUp).row
    Firstrow = J3
    If ActiveCell.row < 3 Then Exit Sub
    If ActiveCell.row > 2 Then
    Range("J3:J"" & LastRowColumnH).End(xlDown).Formula = "=J2-H3"
    End If
    Next
    End With
    End Sub

    If it helps at all this macro seems to work when there is multiple lines of info, but when there is only 1 line it starts J2 - J3 in the actual cell J2 and displays incorrect info.
    Last edited by smitty234; 08-25-2018 at 05:35 PM.

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

    Re: Start Macro in certain row

    Sub ONHAND2()
        Dim ws        As Worksheet
        Dim Lastrow   As Long
        For Each ws In ActiveWorkbook.Worksheets
            LastRowColumnH = ws.Cells(Rows.Count, "H").End(xlUp).Row
            If LastRowColumnH > 2 Then ws.Range("J3:J" & LastRowColumnH).Formula = "=J2-H3"
        Next
    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.

  3. #3
    Registered User
    Join Date
    08-25-2018
    Location
    wisconsin
    MS-Off Ver
    2013
    Posts
    28

    Re: Start Macro in certain row

    Thank you! It is greatly appreciated!

+ 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. [SOLVED] VB Macro - Start macro at cursor location
    By dontaylor in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-14-2016, 07:16 PM
  2. [SOLVED] Macro needs to start at (A1) and not (A2)
    By b_rianv in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-13-2014, 10:03 AM
  3. Replies: 5
    Last Post: 05-04-2013, 01:42 PM
  4. Password Macro + Play Macro on start up
    By rmharrison in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2013, 01:41 AM
  5. Using 1 macro to start another
    By Riley_5000 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-19-2009, 06:59 AM
  6. [SOLVED] How do you start a Macro?
    By Michael in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 06-13-2006, 12:15 PM
  7. [SOLVED] start a macro
    By johnT in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-06-2005, 03:06 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