Results 1 to 7 of 7

VBA - Static code to dynamic

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-13-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2003
    Posts
    152

    VBA - Static code to dynamic

    Hi,

    Please have a look at the attached file, "HB Data" is the original sheet and got the following code from this forum


    Sub check()
    Position = 3
    With Cells(5, 13)
        Select Case Position
            Case 1 To 4:    .Value = Range("B2").Offset(0, Position).Value
            Case Else:      .Value = Range("G2").Value
        End Select
    End With
    
    With Cells(6, 13)
        Select Case Position
            Case 1 To 3:    .Value = Range("C2").Offset(0, Position).Value
            Case Else:      .Value = Range("G2").Value
        End Select
    End With
    
    End Sub
    The above code works fine if I have the data as per the 'HB Data' sheet, I know if additional data added as in the 'HB Data_new' then the above code won't work. So I need to convert the above code to dynamic.

    Kindly help me please.

    Originally I had
    position=3
    Cells(5, 13).Value = "=IF(" & Position = 1 & ",C2,IF(" & Position = 2 & ",D2,IF(" & Position = 3 & ",E2,IF(" & Position = 4 & ",F2,G2))))"
    But it was not working, so I got help and above code from this forum.

    Thanks
    Attached Files Attached Files
    Last edited by gan_xl; 03-06-2014 at 11:53 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Changing code from Static to Dynamic
    By JamesFletcher in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-29-2013, 04:33 AM
  2. [SOLVED] Changing static code to dynamic code
    By JamesFletcher in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2013, 07:31 AM
  3. [SOLVED] Make Static code Dynamic
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-05-2012, 11:09 AM
  4. Static Cell Value in Reference with Dynamic one?
    By Rick-O-Shay in forum Excel General
    Replies: 1
    Last Post: 01-11-2011, 02:50 PM
  5. Turn static RANGE to dynamic
    By Barmoley in forum Excel General
    Replies: 7
    Last Post: 11-14-2010, 04:33 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