+ Reply to Thread
Results 1 to 3 of 3

Thread: Data Conversion Macro

  1. #1
    Registered User
    Join Date
    06-14-2011
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Data Conversion Macro

    Hello,

    I'm new to VBA writing, so please pardon my ignorance.

    I am writing a macro to convert a raw data sheet into a new clean data sheet. This entails taking a response and translating it into a number value so it can be statistically analyzed.

    For example: taking a row of 'yes' or 'no' answers and placing them in the clean sheet in the same location as 1 or 2 respectively.

    My question is how do I approach writing a code that will read a specific row and translate and insert the number value in the same row on another sheet?

    Thank you

  2. #2
    Forum Guru davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2007
    Posts
    1,879

    Re: Data Conversion Macro

    You would use something like this:

    With Sheets("Sheet1")
        If .Cells(i, j).Value = "Yes" Then
            Sheets("Sheet2").Cells(i, j).Value = 1
        Else
            Sheets("Sheet2").Cells(i, j).Value = 0
        End If
    End With
    Where i and j are the row and column numbers. You can use a loop to get through each column and row.
    Also, if you have more than two options for what will be translated onto the second sheet, it may be better to use a Select Case like this:

    With Sheets("Sheet1")
        Select Case .Cells(i, j).Value
            Case "Yes"
                Sheets("Sheet2").Cells(i, j).Value = 1
            Case "No"
                Sheets("Sheet2").Cells(i, j).Value = 0
            Case "Maybe"
                Sheets("Sheet2").Cells(i, j).Value = -1
            Case Else
                Sheets("Sheet2").Cells(i, j).Value = 10
            End Select
    End With
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    06-14-2011
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Data Conversion Macro

    Awesome, much appreciated.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0