Results 1 to 6 of 6
  1. #1
    satswid is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2011
    Posts
    6

    Converting this Excel VBA code to Access VBA. A really challenging task

    Hi guys,
    Earlier I had a excel file with many columns.
    I wrote a code in Excel VBA to fill up the last two columns according to the data in the other columns of the row.
    It worked fine.


    Now, the whole thing is transferred to an Access table.

    Pls help me convert this Excel VBA code to Access VBA.

    Code:
    Sub GeneratePorEngID()
    Range("S2:T5000").Clear
    Dim PrevTaskID As Integer
    Dim intNO As Long
    Dim intCount As Integer
    intNO = 1
    PrevTaskID = 1
    For i = 2 To 5000
    'If PrevTaskID = 1 Then intNO = 1
     
    If Cells(i, "J") <> "" Then
    If PrevTaskID = Cells(i, "J") Then
    Cells(i, "S") = intNO
    intNO = intNO + 1
    intCount = intCount + 1
    Else
    For j = i - intCount - 1 To i - 1
    Cells(j, "T") = intNO
    intNO = intNO + 1
     
    Next
    Cells(i, "S") = intNO
    intNO = intNO + 1
    intCount = 0
    PrevTaskID = Cells(i, "J")
    End If
    End If
    Next
     
    End Sub
    Thanks a ton in advance

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Forget the Excel based code. Just tell us what you want to do with the data. Show sample source data and desired output.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    satswid is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2011
    Posts
    6
    Quote Originally Posted by June7 View Post
    Forget the Excel based code. Just tell us what you want to do with the data. Show sample source data and desired output.
    OK,
    I have a sample table with 3 fields
    For thousands of rows, The first two fields are having data but third field is empty.

    So I need to make a loop using MS-Access VBA to run through each row and set up the value in the 3rd field based on the values in 1st and 2nd field.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    And what determines the value for the 3rd field? What is the criteria?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    satswid is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2011
    Posts
    6
    Quote Originally Posted by June7 View Post
    And what determines the value for the 3rd field? What is the criteria?
    There are some calculations that are need to be done.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    I understand calculations are needed. If we understand your data and the output you want and why, we can advise how. VBA code might not even be needed. Often data can be manipulated within a query to produce desired output.

    What values do you want in third column? What criteria determines the value? Describe narratively what needs to happen. A detailed explanation would have been better than asking us to interpret Excel based code. It looks like you are generating a sequential number. There are several ways to do this in Access, all depends on the purpose.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Converting Excel IF to Access iiF???
    By robertr in forum Queries
    Replies: 5
    Last Post: 10-14-2011, 05:53 AM
  2. Converting Excel VBA to Access VBA
    By jo15765 in forum Programming
    Replies: 10
    Last Post: 10-13-2011, 07:59 PM
  3. Converting to access from Excel
    By Alexpi in forum Database Design
    Replies: 3
    Last Post: 05-24-2011, 02:46 PM
  4. Correct code for challenging dates?
    By thekruser in forum Queries
    Replies: 6
    Last Post: 11-08-2010, 03:38 PM
  5. Converting or using Access as a front end for Excel
    By jacko311 in forum Database Design
    Replies: 4
    Last Post: 11-07-2009, 12:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums