Results 1 to 9 of 9

Left, Mid, Right in VBA across multiple sheets

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-13-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    209

    Left, Mid, Right in VBA across multiple sheets

    Hello,

    I have existing code below that puts the left, mid and right formula in their respective columns on Sheet1.

    Sub test()
    
    
    Dim I As Integer
    Dim M As Integer
    Dim P As Integer
    
    Dim ws As Worksheets
    
    Set wsT = Sheets("Sheet1")
    
    lastrow = wsT.Cells(Rows.Count, 2).End(xlUp).Row ' 2 = column B
    
    
    For I = 7 To lastrow ' 7 = Column G where I want my results to be for the left formula
    For M = 8 To lastrow ' 8 = Column H where I want my results to be for the mid formula
    For P = 9 To lastrow ' 9 = Column I where I want my results to be for the right formula
    
    
    'LEFT
    wsT.Cells(I, 7).Value = Left(wsT.Cells(I, 2))
    
    
    'MID
    wsT.Cells(I, 8).Value = Mid(wsT.Cells(I, 6, 3))
    
    
    'RIGHT
    wsT.Cells(I, 9).Value = Right(wsT.Cells(I, 2))
    
    Next I
    
    
    
    End Sub

    However, when I hit the button to run the code I get this error, "Compile error: Argument not optional".

    What I want to do is loop this code and perform the formulas for all 3 sheets when I press the button. Any ideas? Thx
    Attached Images Attached Images
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] snake single column into multiple columns right to left and left to right
    By Gesssssssss in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-24-2021, 10:10 AM
  2. Renumber sheets in VBA from left to right
    By qwertyyy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2018, 10:47 PM
  3. Replies: 1
    Last Post: 01-05-2017, 10:04 AM
  4. Is sheets(2) the second sheet from the left?
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-01-2015, 07:43 PM
  5. Replies: 1
    Last Post: 02-25-2013, 11:37 AM
  6. Replies: 2
    Last Post: 09-11-2012, 02:02 PM
  7. Right-To-Left sheets
    By bluesdata in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-17-2007, 02:53 PM

Tags for this Thread

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