Change in VBA code

KlausW

Active Member
Joined
Sep 9, 2020
Messages
401
Office Version
  1. 2016
Platform
  1. Windows
Hi, I have a little challenge. I use this VBA code to consolidate my sheets. It works really well.
I would like the data to be inserted in K9, but do not know how to do.
All help will be appreciated.
Best Regards
Klaus W
VBA Code:
Sub Opsamling()
    Dim wksHent As Range
    Dim wksSaml As Worksheet
    Dim sidsterk As Long
    Dim kopiomr  As Range
    Dim kolonner As Variant
    kolonner = Split(Names("HentKolonner").RefersToRange.Value2, ":")
    Set wksSaml = Worksheets(Names("SamlearkNavn").RefersToRange.Value2)
    wksSaml.Cells.ClearContents
    For Each wksHent In Names("OpsamlingFra").RefersToRange.Cells
        sidsterk = Worksheets(wksHent.Value2).Range("A" & Worksheets(wksHent.Value2).Rows.Count).End(xlUp).Row
        'kopi dataomkr
        Set kopiomr = Worksheets(wksHent.Value2).Range(kolonner(0) & "2:" & kolonner(1) & sidsterk)
        wksSaml.Range("k" & wksSaml.Rows.Count).End(xlUp).Offset(1, 0).Resize(kopiomr.Rows.Count, kopiomr.Columns.Count).Value2 = kopiomr.Value2
        'kopi overskrift
        'wksSaml.Range("A1").EntireRow.Value2 = Worksheets(wksHent.Value2).Range("A1").EntireRow.Value2
    Next
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
The line that you want to change is

VBA Code:
wksSaml.Range("k" & wksSaml.Rows.Count).End(xlUp).Offset(1, 0)

This is where you are telling where to put the data. Currently it writes to the row after the last row. If you have a fixed address then simply use that

VBA Code:
wksSaml.Range("K9").Resize(kopiomr.Rows.Count, kopiomr.Columns.Count).Value2 = kopiomr.Value2
 
Upvote 0
The line that you want to change is

VBA Code:
wksSaml.Range("k" & wksSaml.Rows.Count).End(xlUp).Offset(1, 0)

This is where you are telling where to put the data. Currently it writes to the row after the last row. If you have a fixed address then simply use that

VBA Code:
wksSaml.Range("K9").Resize(kopiomr.Rows.Count, kopiomr.Columns.Count).Value2 = kopiomr.Value2
Hi
The line that you want to change is

VBA Code:
wksSaml.Range("k" & wksSaml.Rows.Count).End(xlUp).Offset(1, 0)

This is where you are telling where to put the data. Currently it writes to the row after the last row. If you have a fixed address then simply use that

VBA Code:
wksSaml.Range("K9").Resize(kopiomr.Rows.Count, kopiomr.Columns.Count).Value2 = kopiomr.Value2
Hi

Siddharth Rout it looks like it is works. I will try it to day and return tomorrow. Hav a nice day. Best Regards Klaus, Denmark

 
Upvote 0
Hi

Hi

Siddharth Rout it looks like it is works. I will try it to day and return tomorrow. Hav a nice day. Best Regards Klaus, Denmark

Good morning Siddharth Rout, that's a little challenge. The VBA code only includes data if there is no formula. Where the VBA code is to retrieve the data, there are formulas in the cells. Best regards Klaus W
 
Upvote 0
Good morning Siddharth Rout, that's a little challenge. The VBA code only includes data if there is no formula. Where the VBA code is to retrieve the data, there are formulas in the cells. Best regards Klaus W

Not sure I understand you. Perhaps a screenshot of what you want to achieve may help for an accurate solution?
 
Upvote 0

Forum statistics

Threads
1,216,531
Messages
6,131,209
Members
449,636
Latest member
ajdebm

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