Macro code breakdown

londa_vba

Board Regular
Joined
May 11, 2023
Messages
61
Office Version
  1. 365
Platform
  1. Windows
Hello
I am trying to adjust an export code written by someone else in which the data being exported is the same but the reference location for the data (sheets, rows, and cells) has changed. It would be helpful to know what the code is instructing the macro to do in each line. Specifically what A=3 To 11 means. If Cells(L,A) means row 11 and column 3? Note: L = 11 To 33 portion of the code, I was able to adjust successfully.

VBA Code:
For L = 11 To 33
        Sheets("MME").Select
        numalleles = Application.WorksheetFunction.CountA(Range(Cells(L, 3), Cells(L, 11)))
    If numalleles > 0 Then
        Sheets("Export").Cells(Exportrow, 1) = "<LOCUS>"
        Exportrow = Exportrow + 1
        Sheets("Export").Cells(Exportrow, 1) = "   <LOCUSNAME>" & Sheets("MME").Cells(L, 2) & "</LOCUSNAME>"
        Exportrow = Exportrow + 1
        Sheets("Export").Cells(Exportrow, 1) = "   <READINGBY>" & user & "</READINGBY>"
        Exportrow = Exportrow + 1
        Sheets("Export").Cells(Exportrow, 1) = "   <READINGDATETIME>" & yr & "-" & mn & "-" & dd & "T" & hr & ":" & mi & ":" & sc & "</READINGDATETIME>"
        Exportrow = Exportrow + 1
 For A = 3 To 11
            If Sheets("MME").Cells(L, A) > 0 Then
                Allele = Sheets("MME").Cells(L, A)
                Allele = Replace(Allele, "<", "&lt;")
                Allele = Replace(Allele, ">", "&gt;")
            
                If A = 3 Then
                    Sheets("Export").Cells(Exportrow, 1) = "      <ALLELE ALLELEREQUIRED = " & Chr(34) & "1" & Chr(34) & " > "
                    Exportrow = Exportrow + 1
                    Sheets("Export").Cells(Exportrow, 1) = "      <ALLELEVALUE>" & Allele & "</ALLELEVALUE>"
                    Exportrow = Exportrow + 1
                    Sheets("Export").Cells(Exportrow, 1) = "   </ALLELE>"
                    Exportrow = Exportrow + 1
                Else
                    Sheets("Export").Cells(Exportrow, 1) = "   <ALLELE>"
                    Exportrow = Exportrow + 1
                    Sheets("Export").Cells(Exportrow, 1) = "      <ALLELEVALUE>" & Allele & "</ALLELEVALUE>"
                    Exportrow = Exportrow + 1
                    Sheets("Export").Cells(Exportrow, 1) = "   </ALLELE>"
                    Exportrow = Exportrow + 1
                End If
            End If

        Next A

        Sheets("Export").Cells(Exportrow, 1) = "</LOCUS>"
        Exportrow = Exportrow + 1
    End If
    
Next L

3.PNG


here is a clip of the working export file and what the finished product should look like
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Rather than trying to decipher the code, it would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshots (not pictures) of your two sheets. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
Rather than trying to decipher the code, it would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshots (not pictures) of your two sheets. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
i am not able to download xl2bb on this computer.
current export tab pulls from codis tab. i want to generate export (2) that pulls from codis MTR1 tab with the two export tabs being identical in the end. reference data is the information under item and number (codis MTR1 BA, BB, BC). Note: duplicate numbers are only displayed once. it also should pull user id from settings tab and specimen id from codis MTR1
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,068
Members
449,091
Latest member
remmuS24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top