Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

arranging the code for headers ,borders

0

hello

I need arranging  the  code . it   doesn't  create  the  headers    correctly  when split  the  column C . so  the  code  it  will fill missed items  into column A,B  in sheet DT   based on sheet SUMMARY  and  split  column C into sheet DT  into  columns  C,D,E  with keeping the rest of  columns . so  the  code  should  create  the  headers  when  split  the  column C  and  also  the  borders ,formatting as  I  put  the  right  data in sheet OUTPUT . 

Answer
Discuss

Discussion

Hi Leap.

I'll try to look later but at first glance I don't undersatnd your question. You say "it doesn't create the headers correctly" but your code doesn't seem to write any headers. Can you give a better explanation or perhaps the "before" sheets and (required) expected results?
John_Ru (rep: 6142) Jan 24, '22 at 6:03 am
Hi John, the  orginal  data is  in sheet DT   and  when  run  the  macro  should  show  the  result  in sheet DT based on sheet summary .  as  I  put  in sheet OUPUT . you  can  run  the  macro  and  see how  become  in sheet DT and  compare   with  the  right  data in sheet OUPUT. just  see  the  headers  when  split  column C in sheet DT   you  will find out  they're not  arranged  also  the  same  formmating ,borders .
leap (rep: 46) Jan 24, '22 at 6:22 am
Add to Discussion

Answers

0
Selected Answer

Leap

In your sub Test, I added the lines (in bold) below, within a new With statement. They simply insert new columns and headings (as you requested). The comments are for guidance only and can be deleted once you understand what is happening:

With ws2
    'insert 2 columns
    .Columns("D:E").Insert
    ' Add new headings
    .Range("D1").Value = "TYPE"
    .Range("E1").Value = "MANUFACTURE"

    .Range("A2").Resize(Lr2 - 1, 9).Value = arr

    ' fit columns to content
    .Columns("A:I").AutoFit
End With
Incidentally you have a With Application... End With section but only use .Trim (to get the worksheet function. You don't need this really and can use VBA's Trim method instead. Note that VBA also has LTrim (which deletes spaces only from the left of the string) and RTrim (if you want to remove "trailing" spaces only).

Hope this helps.

Discuss

Discussion

p.s. I assume you realise that your code may lose some rows from worksheet DT. They appear as blanks rows at the bottom (since if there is no match in worksheet summary, you don't add them to your array so it has fewer "rows")
John_Ru (rep: 6142) Jan 24, '22 at 2:09 pm
thanks .  this  fixes  headers problems .
leap (rep: 46) Jan 24, '22 at 3:56 pm
Glad it worked for you Leap.
John_Ru (rep: 6142) Jan 24, '22 at 3:56 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login