Results 1 to 9 of 9

A shorter way to write this macro

Threaded View

light A shorter way to write this... 08-20-2023, 03:10 PM
bsalv Re: A shorter way to write... 08-20-2023, 03:23 PM
light Re: A shorter way to write... 08-20-2023, 03:41 PM
JohnTopley Re: A shorter way to write... 08-20-2023, 03:57 PM
bsalv Re: A shorter way to write... 08-20-2023, 03:56 PM
light Re: A shorter way to write... 08-20-2023, 04:17 PM
JohnTopley Re: A shorter way to write... 08-20-2023, 04:27 PM
light Re: A shorter way to write... 08-20-2023, 04:53 PM
jolivanes Re: A shorter way to write... 08-20-2023, 05:46 PM
  1. #1
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    A shorter way to write this macro

    I have this macro but it seems like there must be a shorter way to do this. I have to write it for "If Cells(X, 161).Value = 1,2,3,4,5,6,7,8,9,10". Note (in the example below) as the if value increases by 1 on the left, the cell values increase by 1 as well on the right.

    Sub Moan()
    finalrow = Cells(Rows.Count, 160).End(xlUp).Row
    For X = 4 To finalrow
    If Cells(X, 161).Value = 1 Then Cells(X, 162).Value = Cells(X, 6).Value
    If Cells(X, 161).Value = 1 Then Cells(X, 163).Value = Cells(X, 17).Value
    If Cells(X, 161).Value = 1 Then Cells(X, 164).Value = Cells(X, 50).Value

    If Cells(X, 161).Value = 1 Then Cells(X, 165).Value = Cells(X, 61).Value
    If Cells(X, 161).Value = 1 Then Cells(X, 166).Value = Cells(X, 72).Value
    If Cells(X, 161).Value = 1 Then Cells(X, 167).Value = Cells(X, 83).Value

    If Cells(X, 161).Value = 2 Then Cells(X, 162).Value = Cells(X, 7).Value
    If Cells(X, 161).Value = 2 Then Cells(X, 163).Value = Cells(X, 18).Value
    If Cells(X, 161).Value = 2 Then Cells(X, 164).Value = Cells(X, 51).Value

    If Cells(X, 161).Value = 2 Then Cells(X, 165).Value = Cells(X, 62).Value
    If Cells(X, 161).Value = 2 Then Cells(X, 166).Value = Cells(X, 73).Value
    If Cells(X, 161).Value = 2 Then Cells(X, 167).Value = Cells(X, 84).Value


    Next X
    End Sub
    Last edited by light; 08-20-2023 at 04:53 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] can i write this formula in a shorter way
    By sharky1978 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 01-09-2023, 10:18 AM
  2. [SOLVED] is there a shorter way to write this else if code that compares 2 combo box values?
    By kevinu in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-24-2018, 07:48 PM
  3. [SOLVED] Shorter or better write CF formula
    By HeyInKy in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-19-2017, 02:09 PM
  4. [SOLVED] how to make a code shorter to write a paragraph
    By eddyrcabrera79 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2015, 01:10 PM
  5. Replies: 3
    Last Post: 09-06-2005, 07:05 AM
  6. Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  7. Replies: 2
    Last Post: 06-23-2005, 07: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