+ Reply to Thread
Results 1 to 10 of 10

Convert excel data to vba code

  1. #1
    Registered User
    Join Date
    12-14-2014
    Location
    Utah, usa
    MS-Off Ver
    2013
    Posts
    8

    Convert excel data to vba code

    I am trying to get data from a generic excel file put in a line of VBA code. I get the data online and it comes in various amounts. I would like to convert the data in batches of various sizes, whatever the amount of data I have at that time. There are 2 pieces of data that go in the vba line. I want the output to be in a way that i can copy/paste it into the file i need it to be in. This is for personal use so nothing fancy needs done.

    I was thinking I would paste the data into excel and click a button to convert however much I had to the proper vba syntax.

    In the generic excel file I need the name, column E, in this set of data. I also need the data in column I. I can format the data however it needs to be easy for whoever might help me with this.

    The format of the conversion is in the picture I uploaded. The data in column e will be put in the " " with text. The data in column I will be put where the number is.

    {["name"] = "ColumnEgoesherewithnospaces",["id"] = column I goes here,["button"] = nil},

    This would be the finished code...

    {["name"] = "SoulbindCacheOpener_Generic_unneeded_name",["id"] = 193484,["button"] = nil},

    I'm sure I've butchered my explanation but I know you will ask if you need to.

    Thanks for your help.
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Convert excel data to vba code

    try

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by k1dr0ck; 12-16-2022 at 08:07 PM.

  3. #3
    Registered User
    Join Date
    12-14-2014
    Location
    Utah, usa
    MS-Off Ver
    2013
    Posts
    8

    Re: Convert excel data to vba code

    Ok, i see the code but im way greener than that. How do i run it and all?

    Its also telling me my macros are disabled which they are not. I have the macros setting on trust everything.
    Last edited by tester3x; 12-16-2022 at 08:50 PM.

  4. #4
    Registered User
    Join Date
    12-14-2014
    Location
    Utah, usa
    MS-Off Ver
    2013
    Posts
    8

    Re: Convert excel data to vba code

    oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh oh...

    I figured it out. It works like a charm. I just need to put it to a button so i dont have to open the developers window. I dont know if there is a way to run it from the sheet without a button.

    Thank you sooooooooo much.

  5. #5
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Convert excel data to vba code

    you run it without a button by pressing ALT+F8 then select the "convert" macro

    you can also rename it to whatever suits you Sub convert() to Sub convert_tester3x()

  6. #6
    Registered User
    Join Date
    12-14-2014
    Location
    Utah, usa
    MS-Off Ver
    2013
    Posts
    8

    Re: Convert excel data to vba code

    I did make a button to run it. I also made a few others. I'll link it here again cuz I need help with another aspect of it.

    Another format that I will use to get the values for the script is:

    h t t p s:**
    www wowhead com*item=21216*smokywood-pastures-extra-special-gift

    The ID number is, well obviously the only numbers in that line. The name is at the end. Leaving the - between words is fine. How can I have the script pull those values out of that line and use them if its pasted in that format AND still do it the other way if it is in the other format.

    I was thinking I could use an IF/THEN. If string begins with https, do this, else do that. That line would be put in column a so i think it would work. I just dont know how to pull those values and use them. I think the if/then would also let me mix the 2 formats together.

    h t t p s:
    **1drv. ms*x*s!ArYQSU2RyboygdpFyOPjyRTPHqco5w?e=A7xBvF

    That is the latest version.

    You'll have to put the link together. Take out the spaces. Put the periods. and replace the * with /. excel forum's wont let me post links yet.

  7. #7
    Registered User
    Join Date
    12-14-2014
    Location
    Utah, usa
    MS-Off Ver
    2013
    Posts
    8

    Re: Convert excel data to vba code

    I guess I could just post the main script since that is where the new stuff would be.

    Sub convert()
    Dim lRow As Long, i, c, LR, x
    Dim item As String
    Dim num As String


    name = Range("M10")
    num = Range("N10")

    bRow = Cells(Rows.Count, 1).End(xlUp).Row




    lRow = Cells(Rows.Count, 1).End(xlUp).Row

    For i = 1 To lRow

    If IsEmpty(Range(name & i)) Then Range(name & i).Value = "Name unknown"

    x = Application.WorksheetFunction.Substitute(Range(name & i), Chr(34), "") 'Substitute (True, “r”, “u”)

    c = Application.WorksheetFunction.Substitute(x, " ", "") 'Substitute (True, “r”, “u”)

    Range("K" & i) = "{[" & Chr(34) & "name" & Chr(34) & "] = " & Chr(34) & "Thanks LITTLEDUDE for SCOpener Scripter__" & c & Chr(34) & ",[" & Chr(34) & "id" & Chr(34) & "] = " & Range(num & i) & ",[" & Chr(34) & "button" & Chr(34) & "] = nil},"

    Next i



    End Sub

  8. #8
    Registered User
    Join Date
    12-14-2014
    Location
    Utah, usa
    MS-Off Ver
    2013
    Posts
    8

    Re: Convert excel data to vba code

    Oh, and I had to add in taking out " cuz there were some names with that in and that throws off the whole script.

  9. #9
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Convert excel data to vba code

    i think its best if you create a new thread with a sample file with a before and after data

  10. #10
    Registered User
    Join Date
    12-14-2014
    Location
    Utah, usa
    MS-Off Ver
    2013
    Posts
    8

    Re: Convert excel data to vba code

    I just figured it out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 11-02-2021, 07:05 AM
  2. [SOLVED] Need VBA code to convert excel data file into .txt file format
    By UHK in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-27-2021, 11:52 AM
  3. Convert Excel Code to Access Code
    By Ruseju in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2016, 02:36 AM
  4. VBA code to convert all data + formatting of entire sheet to VBA code
    By jocanon in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-14-2016, 06:56 PM
  5. VBA Code convert data to tab delimited and write data to text file | Not Working
    By lbl159 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2015, 06:40 AM
  6. [SOLVED] UDF to convert data to code 128 B
    By Safi in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-30-2006, 02:30 AM

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